Migrating AWS Lambda functions to Amazon Linux 2
You can now use the latest version of any of the AWS Lambda runtimes on Amazon Linux 2 (AL2). End-of-life of standard support for Amazon Linux (AL1 for simplicity in this post) is coming in December 2020. As a result, AWS is providing a path for customers to migrate current and future workloads to AL2-supported runtimes.
This blog post covers:
- New runtimes for AL2
- AL1 end-of-life schedule
- Legacy runtime end-of-life schedules
The choice to run a Lambda function on AL1 or AL2 is based upon the runtime. With the addition of the java8.al2 and provided.al2 runtimes, it is now possible to run Java 8 (Corretto), Go, and custom runtimes on AL2. It also means that the latest version of all supported runtimes can now run on AL2.
The following shows how the runtimes are mapped to Amazon Linux versions:
|Runtime||Amazon Linux||Amazon Linux 2 (AL2)|
|Python||python3.7, python3.6, python2.7||python3.8|
|Java||java||java11 (Corretto 11), java8.al2 (Corretto 8)|
Java 8 (Corretto)
Amazon Corretto 8 is a production-ready distribution of the Open Java Development Kit (OpenJDK) 8 and comes with long-term support (LTS). AWS runs Corretto internally on thousands of production services. Patches and improvements in Corretto allows AWS to address real-world service concerns and meet heavy performance and scalability demands.
Developers can now take advantage of these improvements as they develop Lambda functions by using the new Java 8 (Corretto) runtime of java8.al2. You can see the new Java runtimes supported in the Lambda console:
Or, in an AWS Serverless Application Model (AWS SAM) template:
Resources: HelloWorldFunction: Type: AWS::Serverless::Function Properties: CodeUri: HelloWorldFunction Handler: helloworld.App::handleRequest Runtime: java8.al2
The custom runtime for Lambda feature was announced at re:Invent 2018. Since then, developers have created custom runtimes for PHP, Erlang/Elixir, Swift, COBOL, Rust, and many others. Until today, custom runtimes have only used the AL1 environment. Now, developers can choose to run custom runtimes in the AL2 execution environment. To do this, select the provided.al2 runtime value in the console when creating or updating your Lambda function:
Or, in an AWS SAM template:
Resources: HelloWorldFunction: Type: AWS::Serverless::Function Properties: CodeUri: hello-world/ Handler: my.bootstrap.file Runtime: provided.al2
With the addition of the provided.al2 runtime option, Go developers can now run Lambda functions in AL2. As one of the later supported runtimes for Lambda, Go is implemented differently than other native runtimes. Under the hood, Go is treated as a custom runtime and runs accordingly. A Go developer can take advantage of this by choosing the provided.al2 runtime and providing the required bootstrap file.
Using SAM Build to build AL2 functions
With the new sam build options, this is easily accomplished with the following steps:
- Update the AWS Serverless Application Model template to the new provided.al2 runtime. Add the Metadata parameter to set the BuildMethod to makefile.
Resources: HelloWorldFunction: Type: AWS::Serverless::Function Properties: CodeUri: hello-world/ Handler: my.bootstrap.file Runtime: provided.al2 Metadata: BuildMethod: makefile
- Add a MakeFile to the project.
build-HelloWorldFunction: GOOS=linux go build cp hello-world $(ARTIFACTS_DIR)/bootstrap
- Use the sam build command.
A working sample Go application on AL2 can be found here: https://github.com/aws-samples/sessions-with-aws-sam/tree/master/go-al2.
Amazon Linux end-of-life timeline
With the latest runtimes now available on AL2, we are encouraging developers to begin migrating Lambda functions from AL1-based runtimes to AL2-based runtimes. By starting this process now, Lambda functions are running on the latest long-term supported environment.
With AL1, that long-term support is coming to an end. The latest version of AL1, 2018.13, had an original end-of-life date set for June 30, 2020. However, AWS extended this date until December 30, 2020. On this date, AL1 will transition from long-term support (LTS) to a maintenance support period lasting until June 30, 2023. During the maintenance support period, AL1 receives critical and important security updates for a reduced set of packages.
However, AL2 is scheduled for LTS until June 30, 2023 and provides the following support:
- Security updates and bug fixes for all packages in core.
- Maintain user-space application binary interface (ABI) compatibility for core packages.
Legacy runtime end-of-life schedules
As shown in the preceding chart, some runtimes are still mapped to AL1 host operating systems. AWS Lambda is committed to supporting runtimes through their long-term support (LTS) window, as specified by the language publisher. During this maintenance support period, Lambda provides base operating system and patching for these runtimes. After this period, runtimes are deprecated.
According to our runtime support policy, deprecation occurs in two phases:
- Phase 1: you can no longer create functions that use the deprecated runtime. For at least 30 days, you can continue to update existing functions that use the deprecated runtime.
- Phase 2: both function creation and updates are disabled permanently. However, the function continues to be available to process invocation events.
Based on this timeline and our commitment to supporting runtimes through their LTS, the following schedule is followed for the deprecation of AL1-based runtimes:
|python2.7||Current plans to support until AL1 end-of-life|
|ruby2.5||Supported until March 2021|
|java8||Supported until March 2022|
|go1.x||Each major Go release is supported until there are two newer Go releases.|
|dotnetcore2.1||Supported until August 2021|
|provided||Supported until December 2020 with AL1|
AWS is committed to helping developers build their Lambda functions with the latest tools and technology. This post covers two new Lambda runtimes that expand the range of available runtimes on AL2. I discuss the end-of-life schedule of AL1 and why developers should start migrating to AL2 now. Finally, I discuss the remaining runtimes and their plan for support until deprecation, according to the AWS runtime support policy.