How to update runtime for Golang AWS Lambda functions
Amazon Web Services (AWS) is deprecating the go1.x
runtime on Lambda, this is currently scheduled for December 31, 2023. Customers need to migrate their Go based lambda functions to the al2.provided
runtime, which uses Amazon Linux 2 as the execution environment.
Read more at:
https://www.wolfe.id.au/2023/08/09/rip-aws-go-lambda-runtime/
https://aws.amazon.com/blogs/compute/migrating-aws-lambda-functions-from-the-go1-x-runtime-to-the-custom-runtime-on-amazon-linux-2/
How to implement the changes for Bluzone Lambda functions
Step01: Create env var for the runtime config
scripts/global-vars.sh
export RUNTIME="provided.al2"
Step02: Use the runtime config on the create lambda function command
scripts/lambda-create.sh
`
echo "RUNTIME:" $RUNTIME
echo "--- creating function [$BITBUCKET_BRANCH-$FN_NAME]"
aws lambda create-function \
--function-name $BITBUCKET_BRANCH-$FN_NAME \
--runtime "$RUNTIME"
Step03: Rename the binary
Makefile
BIN_PATH=bootstrap
build-lambda:
git config --global url."git@bitbucket.org:bluvision-cloud".insteadOf "https://bitbucket.org/bluvision-cloud"
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(LD_FLAGS) -o $(BIN_PATH) $(CMD_PATH).go
package-lambda: build-lambda
@echo "--- zipping lambda function"
zip lambda.zip main
zip lambda.zip $(BIN_PATH)
Step04: Ignore the binary from version controlling
.gitignore
Step05: Update the aws-lambda-go library
go.mod