Migrate Go Lambda Functions from Deprecated go1.x to Amazon Linux 2
Transitioning to the latest technologies is essential for maintaining robust and efficient serverless applications. With AWS deprecating the older Lambda Golang (go1.x) runtime, it’s critical to move to the more advanced Amazon Linux 2 (provided.al2) runtime. This migration promises enhanced performance, potential cost savings due to the support for the arm64 architecture, and a longer-term support strategy.
The migration process requires updates across several configuration files. Here’s a concise guide to the essential changes you need to implement.
Makefile changes:
- Modify from
amd64
toarm64
to leverage the newer architecture’s efficiency. - Modify your binary paths, replacing
bin/FUNCTION_NAME
withbin/FUNCTION_NAME/bootstrap
to conform to the new runtime’s expectations. - Add a zip section within your Makefile to create a deployable package of your Lambda functions:
zip -j build/lambda/FUNCTION_NAME.zip bin/FUNCTION_NAME/bootstrap
.
Serverless.yml changes:
- Modify the runtime specification from
runtime: go1.x
toruntime: provided.al2
to adopt the new runtime. - Add
architecture: arm64
under theprovider:
section to indicate the desired architecture. - Add
.build/lambda/**
under package exclusions to keep builds clean. - (optional) Add the setting
individually: true
for packaging functions separately, which can help to avoid filename conflicts. - Modify the
functions:
section, changing fromhandler: bin/FUNCTION_NAME
tohandler: bootstrap package: artifact: build/lambda/FUNCTION_NAME.zip
.gitignore changes:
- Add a
build/
entry to avoid tracking compiled artifacts in your repository.
Adopting Amazon Linux 2 for your Lambda functions not only keeps you up-to-date with AWS standards but also potentially speeds up your function runs with the efficiency of the arm64 architecture. This can lead to reduced latency and cost savings.
Migrating isn’t just about keeping up with the current; it’s about optimizing your serverless operations for the future. The updated configuration leads to a smoother development workflow and opens the door to the benefits brought by Amazon Linux 2. With these changes, your Lambda functions will be able to take full advantage of AWS’s innovation, ensuring your applications remain scalable, maintainable, and performant.