AWS Lambda@Edge: Running Lambda code in Edge locations.
27 July 2017 • 2 min read • Blog Post
AWS has recently introduced Lambda@Edge which gives you the possibility to run Lambda code in Edge locations. What does it mean for CloudFront users and what can you achieve with it?
AWS Lambda is a serverless solution that allows you to run code in the Cloud without actually provisioning and managing any servers. Using Lambda, your code is executed only when needed and scales to your needs. You also only pay for the compute time you have used.
Lambda@Edge extends its capability by allowing you to run Lambda code in AWS Edge locations. This gives you the opportunity to deliver a response to your end users at the lowest latency and customise content for a better user experience. From this, your code is triggered by various CloudFront events.
Events that can trigger Lambda@Edge:
- After CloudFront receives a request from a viewer (viewer request)
- Before CloudFront forwards the request to the origin (origin request)
- After CloudFront receives the response from the origin (origin response)
- Before CloudFront forwards the response to the viewer (viewer response)
With Lambda@Edge you can:
- Inspect cookies and rewrite URLs to perform A/B testing.
- Send specific objects to your users based on the User-Agent header.
- Implement access control by looking for specific headers before passing requests to the origin.
- Add, drop, or modify headers to direct users to different cached objects.
- Generate new HTTP responses.
- Cleanly support legacy URLs.
- Modify or condense headers or URLs to improve cache utilisation.
- Make HTTP requests to other Internet resources and use the results to customise responses