A developer is building a mobile fitness application that stores daily user activity summaries in an Amazon DynamoDB table. The table is configured with UserId as the partition key and ActivityDate as the sort key. The developer needs to retrieve the activity summary for a specific user on a specific date in the most efficient and secure manner. Which two actions should the developer take?
- Use the GetItem API operation specifying both the UserId and ActivityDate to retrieve the item.Answer
- Initialize the AWS SDK DynamoDB client using the default credential provider chain.Answer
- CUse the Scan API operation with a filter expression on UserId and ActivityDate to locate the item.
- DHardcode the AWS access key ID and secret access key directly in the DynamoDB client configuration code.
- EStore the application's IAM credentials in AWS Systems Manager Parameter Store as standard unencrypted parameters.
Answer
Use the GetItem API operation specifying both the UserId and ActivityDate to retrieve the item, and initialize the AWS SDK DynamoDB client using the default credential provider chain.
Using the GetItem operation is the most efficient and cost-effective way to retrieve a single item when both the partition key (UserId) and sort key (ActivityDate) are known, consuming only the capacity units required for that single item. Additionally, initializing the AWS SDK DynamoDB client using the default credential provider chain follows security best practices by dynamically loading credentials from IAM roles or environment variables, avoiding the need to hardcode secrets.
Step-by-Step Solution
Key Concept
Efficient item retrieval using GetItem and secure client authentication using the default credential provider chain.