Amazon API Gateway with cache enabled

API Gateway REST API

Create a REST API Gateway with a method-level cache

This pattern deploys an Amazon API Gateway REST API endpoint with a method-level cache.
The GET method on the root resource / is enabled with a cache and TTL (Time-To-Live) of 10 seconds.
Any requests made within this 10 second period will be a cache hit and the cached response will be returned by API Gateway immediately without invoking the Lambda integration.
The Lambda integration returns a timestamp in the header so that it is easy to visualize whether a particular response is being returned as a cached response or as a response from the Lambda integration.

< Back to all patterns

GitHub icon Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Launch Stack

Clone repo

git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/apigw-method-cache

Deploy

sam deploy --guided


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

1. Delete the stack: sam delete --stack-name STACK_NAME.
2. Confirm the stack has been deleted: aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus"

Created by:

Albert Blaya

Albert Blaya

Albert is a Solutions Architect at Amazon Web Services based in Australia.

Follow on LinkedIn