Trabalhar com a criptografia de tabelas do DynamoDB usando a AWS Command Line Interface v2
O exemplo de código a seguir mostra como gerenciar opções de criptografia para tabelas do DynamoDB.
Crie uma tabela com a criptografia padrão.
Crie uma tabela com uma chave gerenciada pelo cliente (CMK).
Atualize as configurações de criptografia da tabela.
Descreva a criptografia da tabela.
- Bash
-
- AWS CLI com script Bash
-
Crie uma tabela com a criptografia padrão.
# 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
Crie uma tabela com uma chave gerenciada pelo cliente (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
Atualize a criptografia da tabela.
# 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
Descreva a criptografia da tabela.
# Describe the table to see encryption settings
aws dynamodb describe-table \
--table-name CustomerData \
--query "Table.SSEDescription"
Para ver uma lista completa dos Guias do desenvolvedor e exemplos de código do SDK da AWS, consulte Usar o DynamoDB com um AWS SDK. Este tópico também inclui informações sobre como começar e detalhes sobre versões anteriores do SDK.