Deploy Lambda@Edge function to CloudFront

Deploy Lambda@Edge function to CloudFront

In this section, we will add CloudFront as a trigger for your Lambda function.

CloudFront Lab

  1. In the same lambda console, you have implemented version 1 of the Lambda function. Click the Add trigger button and select CloudFront.

CloudFront Lab

  1. Click Deploy to Lambda@Edge.

CloudFront Lab

  1. Configure the trigger to use the previously created CloudFront Distribution and Cache Behavior with the following settings:
  • Distribution: <select the distributionID generated from exercise 1>
  • Cache behavior: “/serverless”
  • CloudFront event: Origin request
  • Select “I acknowledge that on deploy a new version of this function will be published with the above trigger and replicated across all available AWS regions.”
  • Click Deploy

CloudFront Lab

  1. Deployment will take approximately 5 minutes to complete for CloudFront distribution. In some cases, you can start testing in less than 5 minutes, depending on your location.

CloudFront Lab

  1. Return to Lambda interface and select Replicas.

CloudFront Lab

  1. Now search for your Lambda function in the Lambda functions list and you will find a Lambda function Replica in us-east-1 for the Lambda function you created.

CloudFront Lab

  1. When you move to other AWS regions, you will find that there is a Lambda function replica in all regions where CloudFront has a Regional Edge Cache. These are the Lambda functions that will be called when your CloudFront distribution executes Lambda@Edge. Once your CloudFront distribution has been deployed, test your CloudFront distribution by accessing Distribution in a browser with a serverless path.

CloudFront Lab