aws-sdk-java-v2-rds
AWS SDK for Java 2.x を使用した AWS RDS(リレーショナルデータベースサービス)の管理パターンを提供します。Amazon RDS データベースインスタンス、スナップショット、パラメータグループ、および各種設定の作成・変更・監視・管理を行う際に使用してください。
description の原文を見る
Provides AWS RDS (Relational Database Service) management patterns using AWS SDK for Java 2.x. Use when creating, modifying, monitoring, or managing Amazon RDS database instances, snapshots, parameter groups, and configurations.
SKILL.md 本文
AWS SDK for Java v2 - RDS Management
Overview
このスキルは、AWS SDK for Java 2.x を使用して Amazon RDS (Relational Database Service) を操作するための包括的なガイダンスを提供します。データベースインスタンス管理、スナップショット、パラメータグループ、RDS操作をカバーしています。
When to Use
- RDS データベースインスタンスの作成、変更、削除
- DB スナップショット、パラメータグループ、設定の管理
- Multi-AZ デプロイメントと自動バックアップのセットアップ
- Lambda 関数から RDS データベースへの接続
- インスタンスステータスとパフォーマンスの監視
Instructions
Amazon RDS を操作するには、以下の手順に従ってください。
- 依存関係を追加 - AWS RDS SDK 依存関係とデータベースドライバーを含める
- RDS クライアントを作成 - 適切なリージョンと認証情報を使用して RdsClient をインスタンス化する
- DB インスタンスを作成 - createDBInstance() を適切な設定で使用する
- セキュリティを設定 - VPC セキュリティグループと暗号化をセットアップする
- バックアップを設定 - 自動バックアップウィンドウと保持期間を設定する
- ステータスを監視 - describeDBInstances() を使用してインスタンスの状態を確認する
- スナップショットを作成 - 大きな変更前に手動スナップショットを取得する
- フェイルオーバーを処理 - 高可用性のために Multi-AZ を設定する
Getting Started
RDS Client Setup
RdsClient は Amazon RDS と相互作用するためのメインエントリーポイントです。
基本的なクライアント作成:
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.rds.RdsClient;
RdsClient rdsClient = RdsClient.builder()
.region(Region.US_EAST_1)
.build();
// クライアントを使用
describeInstances(rdsClient);
// 常にクライアントをクローズする
rdsClient.close();
カスタム設定を使用したクライアント:
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
import software.amazon.awssdk.http.apache.ApacheHttpClient;
RdsClient rdsClient = RdsClient.builder()
.region(Region.US_WEST_2)
.credentialsProvider(ProfileCredentialsProvider.create("myprofile"))
.httpClient(ApacheHttpClient.builder()
.connectionTimeout(Duration.ofSeconds(30))
.socketTimeout(Duration.ofSeconds(60))
.build())
.build();
DB インスタンスの説明
DescribeDbInstancesResponse response = rdsClient.describeDBInstances();
for (DBInstance instance : response.dbInstances()) {
System.out.println(instance.dbInstanceArn() + " - " + instance.dbInstanceStatus());
}
Key Operations
DB インスタンスの作成
CreateDbInstanceRequest request = CreateDbInstanceRequest.builder()
.dbInstanceIdentifier(dbInstanceIdentifier)
.dbName(dbName)
.engine("postgres")
.engineVersion("15.4")
.dbInstanceClass("db.t3.micro")
.allocatedStorage(20)
.masterUsername(masterUsername)
.masterUserPassword(masterPassword)
.publiclyAccessible(false)
.build();
CreateDbInstanceResponse response = rdsClient.createDBInstance(request);
// VALIDATION CHECKPOINT: インスタンスが利用可能になるのを待つ
rdsClient.waiter().waitUntilDBInstanceAvailable(
DescribeDbInstancesRequest.builder().dbInstanceIdentifier(dbInstanceIdentifier).build()
);
System.out.println("Instance " + dbInstanceIdentifier + " is available!");
DB パラメータグループの管理
CreateDbParameterGroupRequest request = CreateDbParameterGroupRequest.builder()
.dbParameterGroupName(groupName)
.dbParameterGroupFamily("postgres15")
.description(description)
.build();
rdsClient.createDBParameterGroup(request);
DB スナップショットの管理
CreateDbSnapshotRequest request = CreateDbSnapshotRequest.builder()
.dbInstanceIdentifier(dbInstanceIdentifier)
.dbSnapshotIdentifier(snapshotIdentifier)
.build();
CreateDbSnapshotResponse response = rdsClient.createDBSnapshot(request);
Integration Patterns
Spring Boot Integration
完全な Spring Boot 統合例については references/spring-boot-integration.md を参照してください。以下が含まれます:
- application properties を使用した Spring Boot 設定
- RDS クライアント Bean 設定
- サービスレイヤーの実装
- REST コントローラーの設計
- 例外処理
- テスト戦略
Lambda Integration
Lambda 統合例については references/lambda-integration.md を参照してください。以下が含まれます:
- 従来の Lambda + RDS 接続
- コネクションプーリング付きの Lambda
- AWS Secrets Manager を使用した認証情報の管理
- RDS 管理用の AWS SDK を使用した Lambda
- セキュリティ設定とベストプラクティス
Advanced Operations
DB インスタンスの変更
ModifyDbInstanceRequest request = ModifyDbInstanceRequest.builder()
.dbInstanceIdentifier(dbInstanceIdentifier)
.dbInstanceClass(newInstanceClass)
.applyImmediately(false)
.build();
rdsClient.modifyDBInstance(request);
DB インスタンスの削除
// VALIDATION CHECKPOINT: インスタンスの存在確認とステータス確認
DBInstance instance = rdsClient.describeDBInstances(
DescribeDbInstancesRequest.builder().dbInstanceIdentifier(dbInstanceIdentifier).build()
).dbInstances().get(0);
if ("available".equals(instance.dbInstanceStatus())) {
DeleteDbInstanceRequest request = DeleteDbInstanceRequest.builder()
.dbInstanceIdentifier(dbInstanceIdentifier)
.skipFinalSnapshot(false)
.finalDBSnapshotIdentifier(snapshotId)
.build();
rdsClient.deleteDBInstance(request);
}
Examples
検証付き完全な RDS インスタンス作成
public String createSecurePostgreSQLInstance(RdsClient rdsClient,
String instanceIdentifier,
String dbName,
String masterUsername,
String masterPassword,
String vpcSecurityGroupId) {
// セキュリティ設定でインスタンスを作成
CreateDbInstanceRequest request = CreateDbInstanceRequest.builder()
.dbInstanceIdentifier(instanceIdentifier)
.dbName(dbName)
.masterUsername(masterUsername)
.masterUserPassword(masterPassword)
.engine("postgres")
.engineVersion("15.4")
.dbInstanceClass("db.t3.micro")
.allocatedStorage(20)
.storageEncrypted(true)
.vpcSecurityGroupIds(vpcSecurityGroupId)
.publiclyAccessible(false)
.multiAZ(true)
.backupRetentionPeriod(7)
.deletionProtection(true)
.build();
rdsClient.createDBInstance(request);
// VALIDATION: インスタンスの利用可能性を待つ
rdsClient.waiter().waitUntilDBInstanceAvailable(
DescribeDbInstancesRequest.builder().dbInstanceIdentifier(instanceIdentifier).build()
);
System.out.println("Instance " + instanceIdentifier + " is available!");
return instanceIdentifier;
}
Best Practices
セキュリティ: 暗号化を有効にする (storageEncrypted=true)、VPC セキュリティグループを使用、パブリックアクセスを無効にする。
高可用性: 本番ワークロードのために Multi-AZ を有効にする。
バックアップ: 7日以上の保持期間で自動バックアップを設定する。
削除保護: 本番データベースに対して deletionProtection(true) を有効にする。
リソース管理: try-with-resources でクライアントを常にクローズする:
try (RdsClient rdsClient = RdsClient.builder().region(Region.US_EAST_1).build()) {
// クライアントを使用
}
Dependencies
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>rds</artifactId>
<version>2.20.0</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.6.0</version>
</dependency>
Reference Documentation
詳細な API リファレンスについては、以下を参照してください:
API Reference- 完全な API ドキュメンテーションとデータモデルSpring Boot Integration- Spring Boot パターンと例Lambda Integration- Lambda 関数パターンとベストプラクティス
Error Handling
一般的な例外、エラーレスポンス構造、ページネーション対応を含む包括的なエラー処理パターンについては、API Reference を参照してください。
Constraints and Warnings
- インスタンスの制限: リージョンあたりの DB インスタンス数に対するアカウント制限
- Multi-AZ コスト: 計算コストがおよそ2倍になる
- スナップショットコスト: 手動スナップショットは使用ストレージあたりで課金される
- 削除保護: 保護が有効なインスタンスは削除できない
- メンテナンスウィンドウ: アップデート中はインスタンスが利用できない場合がある
ライセンス: MIT(寛容ライセンスのため全文を引用しています) · 原本リポジトリ
詳細情報
- 作者
- giuseppe-trisciuoglio
- ライセンス
- MIT
- 最終更新
- 不明
Source: https://github.com/giuseppe-trisciuoglio/developer-kit / ライセンス: MIT
関連スキル
superpowers-streamer-cli
SuperPowers デスクトップストリーマーの npm パッケージをインストール、ログイン、実行、トラブルシューティングできます。ユーザーが npm から `superpowers-ai` をセットアップしたい場合、メールまたは電話でサインインもしくはアカウント作成を行いたい場合、ストリーマーを起動したい場合、表示されたコントロールリンクを開きたい場合、後で停止したい場合、またはソースコードへのアクセスなしに npm やランタイムの一般的な問題から復旧したい場合に使用します。
catc-client-ops
Catalyst Centerのクライアント操作・監視機能 - 有線・無線クライアントのリスト表示・フィルタリング、MACアドレスによる詳細なクライアント検索、クライアント数分析、時間軸での分析、SSIDおよび周波数帯によるフィルタリング、無線トラブルシューティング機能を提供します。MACアドレスやIPアドレスでのクライアント検索、サイト別やSSID別のクライアント数集計、無線周波数帯の分布分析、Wi-Fi信号の問題調査が必要な場合に活用できます。
ci-cd-and-automation
CI/CDパイプラインの設定を自動化します。ビルドおよびデプロイメントパイプラインの構築または変更時に使用できます。品質ゲートの自動化、CI内のテストランナー設定、またはデプロイメント戦略の確立が必要な場合に活用します。
shipping-and-launch
本番環境へのリリース準備を行います。本番環境へのデプロイ準備が必要な場合、リリース前チェックリストが必要な場合、監視機能の設定を行う場合、段階的なロールアウトを計画する場合、またはロールバック戦略が必要な場合に使用します。
linear-release-setup
Linear Releaseに向けたCI/CD設定を生成します。リリース追跡の設定、LinearのCIパイプライン構築、またはLinearリリースとのデプロイメント連携を実施する際に利用できます。GitHub Actions、GitLab CI、CircleCIなど複数のプラットフォームに対応しています。
tracking-application-response-times
API エンドポイント、データベースクエリ、サービスコール全体にわたるアプリケーションのレスポンスタイムを追跡・最適化できます。パフォーマンス監視やボトルネック特定の際に活用してください。「レスポンスタイムを追跡する」「API パフォーマンスを監視する」「遅延を分析する」といった表現で呼び出せます。