AWS Command Line Interface v2 を使用して DynamoDB テーブルの暗号化を操作する
次のコード例は、DynamoDB テーブルの暗号化オプションを管理する方法を示しています。
デフォルトの暗号化を使用してテーブルを作成します。
カスタマーマネージド CMK を使用してテーブルを作成します。
テーブルの暗号化設定を更新します。
テーブルの暗号化について説明します。
- Bash
-
- Bash スクリプトを使用した AWS CLI
-
デフォルトの暗号化を使用してテーブルを作成します。
# Create a table with default encryption (AWS owned key) aws dynamodb create-table \ --table-name CustomerData \ --attribute-definitions \ AttributeName=CustomerID,AttributeType=S \ --key-schema \ AttributeName=CustomerID,KeyType=HASH \ --billing-mode PAY_PER_REQUEST \ --sse-specification Enabled=true,SSEType=KMS
カスタマーマネージド CMK を使用してテーブルを作成します。
# Step 1: Create a customer managed key in KMS aws kms create-key \ --description "Key for DynamoDB table encryption" \ --key-usage ENCRYPT_DECRYPT \ --customer-master-key-spec SYMMETRIC_DEFAULT # Store the key ID for later use KEY_ID=$(aws kms list-keys --query "Keys[?contains(KeyArn, 'Key for DynamoDB')].KeyId" --output text) # Step 2: Create a table with the customer managed key aws dynamodb create-table \ --table-name SensitiveData \ --attribute-definitions \ AttributeName=RecordID,AttributeType=S \ --key-schema \ AttributeName=RecordID,KeyType=HASH \ --billing-mode PAY_PER_REQUEST \ --sse-specification Enabled=true,SSEType=KMS,KMSMasterKeyId=$KEY_ID
テーブルの暗号化を更新します。
# Update a table to use a different KMS key aws dynamodb update-table \ --table-name CustomerData \ --sse-specification Enabled=true,SSEType=KMS,KMSMasterKeyId=$KEY_ID
テーブルの暗号化について説明します。
# Describe the table to see encryption settings aws dynamodb describe-table \ --table-name CustomerData \ --query "Table.SSEDescription"
-
API の詳細については、「AWS CLI コマンドリファレンス」の以下のトピックを参照してください。
-
AWS SDK デベロッパーガイドとコード例の詳細なリストについては、「AWS SDK で DynamoDB を使用する」を参照してください。このトピックには、使用開始方法に関する情報と、以前の SDK バージョンの詳細も含まれています。
リソースのタグ付けを操作する
サーバーレスサンプル