Building a Versioned Lambda Deployment Script With the AWS CLI

https://hackernoon.imgix.net/images/GKMDC80avThn4WCIH2KxmeCMx9o1-s982cqn.png

You've got a Lambda running in production and a shiny new image sitting in ECR. The lazy move is to update the image URI, walk away, and hope for the best. The problem is that this swaps the code for everyone, instantly, with no safety net. If the new version is broken, congratulations, it's broken for 100% of your traffic before you even finish your coffee. What you might be looking for is to publish an immutable version, then shift traffic onto it in a controlled way, all from a single script and preferably in an automated manner.

The script

set -euo pipefailaws lambda wait function-updated-v2 --function-name "$1"aws lambda update-function-code --function-name "$1" --image-uri "$3"aws lambda wait function-updated-v2 --function-name "$1"PUBLISHED_VERSION=$(aws lambda publish-version --function-name "$1" | jq -r '.Version')aws lambda wait published-version-active --function-name "$1" --qualifier "$PUBLISHED_VERSION"VERSIONS=$(aws lambda list-versions-by-function --function-name "$1")CURRENT_VERSION="$(aws lambda get-alias --function-name "$1" --name LIVE | jq -r '.FunctionVersion')"TARGET_VERSION=$(echo "$VERSIONS" |...

Copyright of this story solely belongs to hackernoon.com. To see the full text click HERE

Read more