Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Write and create a Lambda@Edge function

Focus mode
Write and create a Lambda@Edge function - Amazon CloudFront

To use Lambda@Edge, you write the code for your AWS Lambda function. To help you write Lambda@Edge functions, see the following resources:

The programming model for using Node.js or Python with Lambda@Edge is the same as using Lambda in an AWS Region. For more information, see Building Lambda functions with Node.js or Building Lambda functions with Python in the AWS Lambda Developer Guide.

In your Lambda@Edge function, include the callback parameter and return the applicable object for request or response events:

  • Request events – Include the cf.request object in the response.

    If you're generating a response, include the cf.response object in the response. For more information, see Generate HTTP responses in request triggers.

  • Response events – Include the cf.response object in the response.

After you write your own code or use one of the examples, you then create the function in Lambda. To create a function or edit an existing one, see the following topics:

After you create the function in Lambda, you set up Lambda to run the function based on specific CloudFront events, which are called triggers. For more information, see Add triggers for a Lambda@Edge function.

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.