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

Get Started Creating and Using Lambda@Edge Functions

You can use Lambda@Edge functions to do lots of useful things, but it can seem a little complicated when you're getting started. This section explains, at a high level, how Lambda@Edge works with CloudFront and provides a tutorial that steps through a simple example.


After you're familiar with how Lambda@Edge works and you've created a Lambda@Edge function, 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.

Here's an overview of how to create and use Lambda functions with CloudFront:

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

  2. You save and publish a numbered version of the function.

    If you want to make changes to 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. You choose the CloudFront distribution and cache behavior that the function applies to, and then specify one or more CloudFront events, known as 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 replicates the function to AWS locations around the world.

				Conceptual graphic that shows how you create Lambda functions that integrate with CloudFront.