Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
Work with DynamoDB table encryption using Amazon Command Line Interface v2
The following code example shows how to manage encryption options for DynamoDB tables.
Create a table with default encryption.
Create a table with a customer managed CMK.
Update table encryption settings.
Describe table encryption.
- Bash
-
- Amazon CLI with Bash script
-
Create a table with default encryption.
# 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
Create a table with a customer managed 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 table encryption.
# 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 table encryption.
# Describe the table to see encryption settings
aws dynamodb describe-table \
--table-name CustomerData \
--query "Table.SSEDescription"
For a complete list of Amazon SDK developer guides and code examples, see
Using this service with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.