Get started creating and using 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 creating and using 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. For a step-by-step tutorial, see Tutorial: Creating a simple Lambda@Edge function.

  1. In the Amazon Lambda console, create a Lambda function in the US East (N. Virginia) Region. (Or you can create the function programmatically by using one of the Amazon SDKs.)

  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

Learn more about how you can use Lambda@Edge for your own custom solutions. Learn more about 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.