A developer is writing a backend service that needs to encrypt a sensitive JSON configuration payload of before writing it to an Amazon DynamoDB table. The encryption must be performed client-side using AWS KMS, minimizing latency and the number of AWS API calls.
Which approach meets these requirements most efficiently?
- ACall the KMS GenerateDataKey API to retrieve a data key, encrypt the JSON payload locally using the plaintext key, and store the encrypted data key along with the ciphertext in the DynamoDB table.
- Call the KMS Encrypt API directly using a customer managed key, and store the resulting ciphertext in the DynamoDB table.Answer
- CCall the KMS GenerateDataKeyWithoutPlaintext API to obtain an encrypted data key, call the Decrypt API to retrieve the plaintext key, encrypt the JSON payload locally, and store it in the DynamoDB table.
- DStore the JSON configuration payload in AWS Secrets Manager as a secret, configure automatic rotation, and retrieve the secret using a DynamoDB stream trigger on every write operation.
Answer
Call the KMS Encrypt API directly using a customer managed key, and store the resulting ciphertext in the DynamoDB table.
The correct option is to call the KMS Encrypt API directly because the payload size () is less than the limit for direct KMS encryption. This approach minimizes latency by requiring only one API call and removes the complexity of managing envelope encryption keys locally.
Step-by-Step Solution
Key Concept
AWS KMS direct encryption capability and its payload limit.