Adding triggers by using the CloudFront console - 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).

Adding triggers by using the CloudFront console

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 Amazon Web Services Management Console and open the Amazon Lambda console at https://console.amazonaws.cn/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. On the Function overview page, 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. Choose the Copy ARN button to copy the ARN to your clipboard. The ARN for the Lambda function looks something like this:

      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.amazonaws.cn/cloudfront/v4/home.

  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 cache behavior that you want to add triggers to, and then choose Edit.

  6. For Function associations, in the Function type list, choose Lambda@Edge for when you want the function to execute: for viewer requests, viewer responses, origin requests, or origin responses.

    For more information, see How to decide which CloudFront event to use to trigger a Lambda@Edge function.

  7. In the Function ARN / Name text box, paste the ARN of the Lambda function that you want to execute when the chosen event occurs. This is the value that you copied from the Lambda console.

  8. Select Include body if you want to access the request body in your function.

    If you just want to replace the request body, you don't need to select this option.

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

  10. Choose Save changes.

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

    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 Deploying to the time and date of deployment.