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={}