Skip to content

Instantly share code, notes, and snippets.

@farhad-taran
Last active May 7, 2021 14:11
Show Gist options
  • Save farhad-taran/aa56ec0c69bfd3ee15a2db06b2f5de39 to your computer and use it in GitHub Desktop.
Save farhad-taran/aa56ec0c69bfd3ee15a2db06b2f5de39 to your computer and use it in GitHub Desktop.
AWS Lambda CLI commands for doing Canary deployments

I have written the following reusable scripts which can be used to aid with canary deployment of AWS Lambdas.

Get the latest version number of a lambda:

latest_version=$(aws lambda list-versions-by-function --function-name lambda-test \
  --no-paginate \
  --query "max_by(Versions, &to_number(to_number(Version) || '0'))" | jq -r ".Version")
  
echo "Latest version is: ${latest_version}"

The previous version number is obviously:

previous_version=$(($latest_version-1))

echo "Previous version is: ${previous_version}"

Set the traffic on the previous version to 50% which means the latest version will also have a traffic of 50%:

aws lambda update-alias --name LATEST --function-name lambda-test --routing-config AdditionalVersionWeights={${previous_version}=0.5}

Roll-Forward or set all traffic to the latest new version:

aws lambda update-alias --name LATEST --function-name lambda-test --routing-config AdditionalVersionWeights={}

Roll-Backward or set all traffic to the previous version:

aws lambda update-alias --name LATEST --function-name lambda-test --function-version ${previous_version} --routing-config AdditionalVersionWeights={}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment