Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

awscli - lambda function update trigger

We have a lambda@edge function which listens to cloudfront distribution origin request and response events. We are trying to automate the deployment. So far we succeeding in updating the code and publishing the new version.

  - npm install
  - zip -r lambda.zip *
  - aws lambda update-function-code --function-name LambdaFunction1 --zip-file fileb://lambda.zip
  - aws lambda publish-version --function-name LambdaFunction1

But how do we update CloudFront triggers to point to the latest published version?

like image 586
adnan kamili Avatar asked Jun 21 '18 11:06

adnan kamili


People also ask

How do you update Lambda function runtime?

To change the runtime, you create a new container image. When you use a . zip file archive for the deployment package, you choose a runtime when you create the function. To change the runtime, you can update your function's configuration.

Can Lambda update itself?

Using our solution, the pipeline automatically updates the Lambda code for you without requiring you to copy, compress, and upload . zip files to Amazon S3.


1 Answers

Perform the following steps-

  1. Check the versions of lambda first by running the following cli command. And the Fetch the FunctionARN of the latest version.

aws lambda list-versions-by-function --function-name LAMBDA_NAME

  1. Get the cloudfront distribution json data first by the following command.

aws cloudfront get-distribution-config --id DISTRIBUTION_ID > cf_config.json

  1. Create a file named updated_cf_config.json by fetching DistributionConfig key from the cf_config.json.

  2. Now Put the FunctionARN of the latest Version of lambda inside the "LambdaFunctionAssociations" -> "LambdaFunctionARN"

  3. Update cloudfront distribution by running the command. To update the cloudfront distribution we need ETAG from cf_config.json:

aws cloudfront update-distribution --distribution-config file://cf_config.json --id DISTRIBUTION_ID --if-match ETAG

like image 126
Aastha Avatar answered Oct 16 '22 16:10

Aastha