Navigating AWS Lambda Go 1.x Runtime Deprecation with Ease
Written on
Chapter 1: Understanding Runtime Deprecation
AWS has made the decision to discontinue support for the Go 1.x runtime in Lambda, which may feel like an unwelcome surprise. However, this shift could actually provide some advantages.
As AWS refines its offerings, it seems to be letting go of technologies that present significant support challenges. The migration from the Go 1.x runtime to the provided.al2 option aligns with AWS's strategy to bolster support for native-compiled languages such as Rust and C++. Regardless, if your Lambda function relies on Go 1.x, addressing this transition should be a top priority.
Section 1.1: Benefits of Migrating to Provided.al2
There are at least two notable benefits to switching over to the provided.al2 runtime.
First, if you haven't yet adopted the ARM64 architecture, this is an ideal chance to do so. ARM64 is not only cost-effective, but Oracle even offers powerful ARM64 servers at no charge! For more information, check out the following video:
AWS also claims that their Graviton (ARM64 CPU) delivers improved performance. While the difference might not be immediately apparent with smaller Lambda functions, I recommend analyzing performance data over an extended period to understand the cumulative benefits of this new architecture.
Second, by utilizing the provided.al2 runtime, you can eliminate the extra mediator component that exists in Go 1.x, resulting in quicker Lambda invocations and a leaner code package.
Section 1.2: A Simplified Migration Process
Fortunately, my guide simplifies this process significantly, so there's no need to wait until New Year's Eve to make the switch.
If your Lambda code is located in a file named lambda.go, you can compile it using the following command:
GOOS=linux GOARCH=arm64 go build -tags lambda.norpc -o bootstrap lambda.go
Specifying GOOS=linux and GOARCH=arm64 ensures that your Lambda function runs in a Linux environment using ARM64 architecture, which Go can facilitate.
By adding the -tags lambda.norpc option, you instruct Go to exclude the RPC module from the AWS Go SDK, which helps in reducing the size of the code package. This optimization allows the Lambda Runtime to call the code directly within a single process rather than relying on an additional RPC mediator.
Finally, package your compiled code into a zip file:
zip lambda.zip bootstrap
To deploy the Lambda function, I utilize Terraform. Here’s a sample template for the variables that require updates for the new runtime:
resource "aws_lambda_function" "go-lambda" {
...
s3_key = ".../lambda.zip" # the zip file created in the previous step
handler = "bootstrap" # the file inside the zip, must be named 'bootstrap'
runtime = "provided.al2"
architectures = ["arm64"]
...
}
If you're using CloudFormation or SAM, you would adjust the same values accordingly. For those who prefer the AWS Console, you will need to upload the zip file via the Lambda console and update the handler, runtime, and architecture settings.
For more detailed insights on the deprecation of the Go runtime and how to navigate this transition, I recommend checking the official AWS blog, which offers a comprehensive overview. My goal here was to present my approach in the simplest way possible.
Chapter 2: Quick Tips for a Smooth Transition
To further assist you, here’s another video that covers transitioning the AWS Lambda runtime in a quick manner: