Search code examples
amazon-web-servicesamazon-cloudfrontaws-lambda-edge

How to update lambda@edge ARN in cloudfront distribution using CLI


I would like to update the cloudfront distribution with the latest lambda@edge function using CLI.

I saw this documentation, but could not figure out how to update the lambda ARN only.

Can some one help?


Solution

  • Something like this:

    #!/bin/bash
    set -x
    TEMPDIR=$(mktemp -d)
    CONFIG=$(aws cloudfront get-distribution-config --id CGSKSKLSLSM)
    ETAG=$(echo "${CONFIG}" | jq -r '.ETag')
    echo "${CONFIG}" | jq '.DistributionConfig' > ${TEMPDIR}/orig.json
    echo "${CONFIG}" | jq '.DistributionConfig | .DefaultCacheBehavior.LambdaFunctionAssociations.Items[0].LambdaFunctionARN= "arn:aws:lambda:us-east-1:xxxxx:function:test-func:3"' > ${TEMPDIR}/updated.json
    aws cloudfront update-distribution --id CGSKSKLSLSM --distribution-config file://${TEMPDIR}/updated.json --if-match "${ETAG}"