Menu
Amazon CloudFront
Developer Guide (API Version 2016-09-29)

What Is Lambda@Edge?

AWS Lambda is a compute service that lets you run code in the AWS Cloud without provisioning or managing servers. AWS Lambda executes your code only when needed and scales automatically, from a few requests per day to thousands per second.

Lambda@Edge allows you to run Lambda functions at the AWS edge locations in response to CloudFront events. Without Lambda@Edge, customized processing requires requests to be forwarded back to compute resources at the centralized servers. This slows down the user experience.

Lambda@Edge supports Node.js, which is a server-side JavaScript framework. You can use Lambda functions to respond to four different trigger points for a CloudFront request:

  • When a request is first received from a viewer (viewer request)

  • When the Lambda function forwards a request to the origin (origin request)

  • When the Lambda function receives a response from the origin (origin response)

  • Before the Lambda function responds to the viewer (viewer response)

With Lambda@Edge, you can do the following in response to CloudFront events:

  • Write Lambda functions that inspect cookies in order to rewrite URLs to different versions of a site for A/B testing

  • Send different objects to your users based on the user-agent header (for example, send images that have different resolutions to users based on their devices)

  • Inspect headers or authorized tokens, inserting a corresponding header enabling access control before forwarding a request to the origin

  • Add, drop, and modify headers, and rewrite URL paths to direct users to different objects in the cache

For more information about setting up CloudFront with Lambda@Edge, see Lambda@Edge in the AWS Lambda Developer Guide.