Get started with Lambda@Edge functions - Amazon CloudFront
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Get started with Lambda@Edge functions

With Lambda@Edge, you can use CloudFront triggers to invoke a Lambda function. When you associate a CloudFront distribution with a Lambda function, CloudFront intercepts requests and responses at CloudFront edge locations and runs the function. Lambda functions can improve security or customize information close to your viewers to improve performance.

The following list provides a basic overview of how to create and use Lambda functions with CloudFront.

Overview: Creating and using Lambda functions with CloudFront
  1. Create a Lambda function in the US East (N. Virginia) Region.

  2. Save and publish a numbered version of the function.

    If you want to change the function, you must edit the $LATEST version of the function in the US East (N. Virginia) Region. Then, before you set it up to work with CloudFront, you publish a new numbered version.

  3. Associate the function with a CloudFront distribution and cache behavior. Then specify one or more CloudFront events (triggers) that cause the function to execute. For example, you can create a trigger for the function to execute when CloudFront receives a request from a viewer.

  4. When you create a trigger, Lambda creates replicas of the function at Amazon locations around the world.

Tip

For more information, see creating and updating functions, the event structure, and adding CloudFront triggers. You can also find more ideas and get code samples in Lambda@Edge example functions.

For a step-by-step tutorial, see the following topic: