A developer is designing a serverless e-commerce application. The application has a public API endpoint hosted on Amazon API Gateway that triggers an AWS Lambda function. The Lambda function queries an Amazon DynamoDB table to retrieve a list of active discount codes. This discount list is read-heavy, updated only once per day, and must be returned with sub-second response times. During peak shopping events, the API Gateway endpoint experiences high latency and DynamoDB triggers provisioned throughput exceptions. The developer wants to implement a caching solution that minimizes costs and reduces the load on both the Lambda function and the DynamoDB table.
Which caching strategy should the developer implement to meet these requirements?
- AProvision an Amazon DynamoDB Accelerator (DAX) cluster to cache the read queries from the DynamoDB table.
- Enable Amazon API Gateway stage-level caching with a Time to Live (TTL) of 24 hours.Cevap
- CInitialize a global variable inside the AWS Lambda function to cache the list in the execution context.
- DPerform a DynamoDB Scan operation within the Lambda function and cache the results in the AWS Systems Manager Parameter Store.
Cevap
Enable Amazon API Gateway stage-level caching with a Time to Live (TTL) of 24 hours.
Enabling caching at the Amazon API Gateway stage level is the most cost-effective and low-latency solution. When API Gateway caching is enabled, API Gateway caches responses from the backend (Lambda and DynamoDB) for the specified Time to Live (TTL). If a cache hit occurs, API Gateway returns the response directly to the client without invoking the AWS Lambda function or querying the Amazon DynamoDB table. This eliminates Lambda execution costs and DynamoDB read unit charges for all cached requests, while providing the lowest latency.
Adım Adım Çözüm
Anahtar Kavram
Caching at the API Gateway layer to minimize downstream serverless execution and database costs.