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

Creating Lambda Functions and Adding Triggers

To use Lambda@Edge, you create Lambda functions and add triggers. If you use the AWS console, note the following:

  • You can use only the AWS Lambda console to create Lambda functions.

  • You can use either the AWS Lambda console or the CloudFront console to add triggers.

You can also perform all operations programmatically. For more information, see the following documentation:

Creating Lambda Functions (Console)

For information about creating Lambda functions in the AWS Lambda console, see AWS Lambda@Edge in the AWS Lambda Developer Guide.

Adding Triggers for CloudFront Events to a Lambda Function

You can add triggers for CloudFront events with either the AWS Lambda console or the CloudFront console.

Adding Triggers for CloudFront Events (AWS Lambda Console)

For information about adding triggers for CloudFront events in the Lambda console, see AWS Lambda@Edge in the AWS Lambda Developer Guide.

Adding Triggers for CloudFront Events (CloudFront Console)

To add triggers for CloudFront events in the CloudFront console, perform the following procedure.

To add triggers for CloudFront events to a Lambda function (CloudFront console)

  1. Get the ARN of the Lambda function that you want to add triggers for:

    1. Sign in to the AWS Management Console and open the AWS Lambda console at https://console.aws.amazon.com/lambda/.

    2. In the list of regions at the top of the page, choose US East (N. Virginia).

    3. In the list of functions, choose name of the function that you want to add triggers to.

    4. Choose Qualifiers, choose the Versions tab, and choose the numbered version that you want to add triggers to.

      Important

      You can add triggers only to a numbered version, not to $LATEST.

    5. Copy the ARN that appears at the top of the page, for example:

      arn:aws:lambda:us-east-1:123456789012:function:TestFunction:2

      The number at the end (2 in this example) is the version number of the function.

  2. Open the CloudFront console at https://console.aws.amazon.com/cloudfront/.

  3. In the list of distributions, choose the ID of the distribution that you want to add triggers to.

  4. Choose the Behaviors tab.

  5. Select the check box for the cache behavior that you want to add triggers to, and then choose Edit.

  6. At Lambda Function Associations, in the Event Type list, choose when you want the function to execute: for viewer requests, viewer responses, origin requests, or origin responses.

    For more information, see How You Decide Which CloudFront Event to Use to Trigger a Lambda Function.

  7. Paste the ARN of the Lambda function that you want to execute when the chosen event occurs. This is the value that you copied in step 1.

  8. To execute the same function for more event types, choose + and repeat steps 6 and 7.

  9. Choose Yes, Edit.

  10. To add triggers to more cache behaviors for this distribution, repeat steps 5 through 9.

    The function starts to process requests for the specified CloudFront events when the updated CloudFront distribution is deployed. To determine whether a distribution is deployed, choose Distributions in the navigation pane. When a distribution is deployed, the value of the Status column for the distribution changes from In Progress to Deployed.