An API designed with Amazon API Gateway and AWS Lambda retrieves product details from an Amazon DynamoDB table. The product data changes infrequently, but sudden traffic spikes occasionally cause throttling on the DynamoDB table. The developer wants to implement a caching solution at the API Gateway layer to minimize Lambda invocations and DynamoDB read load. Additionally, client applications must be able to occasionally bypass this cache to retrieve the most up-to-date data when a user manually refreshes the page. Which approach should the developer implement to meet these requirements?
- Enable API Gateway caching for the stage. Configure the API Gateway policy to allow cache invalidation, and instruct client applications to include the Cache-Control: max-age=0 header in their requests.Answer
- BImplement an Amazon DynamoDB Accelerator (DAX) cluster in front of the DynamoDB table, and configure client applications to run a DynamoDB Scan operation with a filter expression when bypassing the cache.
- CCache the product details within the AWS Systems Manager Parameter Store, and configure the Lambda function to retrieve the configurations from Parameter Store instead of DynamoDB on every invocation.
- DStore the product details in static variables within the AWS Lambda function's global execution context, and rely on execution context reuse to serve cached data or clear the variables on timeout.
Answer
Enable API Gateway caching for the stage. Configure the API Gateway policy to allow cache invalidation, and instruct client applications to include the Cache-Control: max-age=0 header in their requests.
The correct option addresses the requirement to cache at the API Gateway layer to prevent Lambda invocations and DynamoDB reads. It leverages the native API Gateway caching feature and allows authorized clients to bypass the cache by passing the Cache-Control: max-age=0 header, which triggers a backend fetch.
Step-by-Step Solution
Key Concept
API Gateway Caching and Cache Invalidation
Estimated Time:1m 30s