A developer is optimizing an AWS Lambda function that queries Amazon DynamoDB for product catalog data. The data changes at most once per hour, but the Lambda function is invoked thousands of times per minute, causing high DynamoDB read costs. The developer wants to add an in-memory caching layer that requires minimal code changes and supports automatic cache invalidation based on TTL. Which service should the developer use?
- A. Amazon ElastiCache for Redis, accessed directly from the Lambda function using the ElastiCache client library.
- B. DynamoDB Accelerator (DAX), by replacing the DynamoDB client in the Lambda function with the DAX client.✓ Correct
- C. Amazon CloudFront with a custom origin pointing to DynamoDB.
- D. AWS AppSync with response caching enabled at the API level.
Explanation
DAX is a fully managed, DynamoDB-compatible in-memory cache that sits transparently between the application and DynamoDB. Switching from the standard DynamoDB SDK client to the DAX client is a minimal code change, and DAX automatically caches reads with a configurable TTL. When the TTL expires, DAX fetches fresh data from DynamoDB, providing automatic invalidation. ElastiCache for Redis requires the developer to write explicit cache-check, cache-populate, and TTL management logic, representing significantly more code changes, and it also requires VPC configuration for Lambda. CloudFront cannot directly query DynamoDB; it caches HTTP responses from origins and is not applicable here. AWS AppSync is a GraphQL API service and is not designed to cache DynamoDB reads invoked directly by a Lambda function.