Java 14 support for AWS Lambda

AWS is currently the most popular choice for serverless applications, but the Java Runtime is hopelessly outdated. Why wait for Amazon to fix this, when theres’s a much better solution? The frgaal project is ready to give you all of that in a safe and simple way.

It’s been less than a year that Amazon finally updated it’s Java Lambda runtime to Java 11 and nothing happened since then. Apparently only LTS versions will be supported. If the trend continues, we’ll get a Java 15 Lambda runtime sometime in 2022. Until then, you’ll either have to work with an ancient SDK 11, or wait for Amazon to update their runtime before you can use all the nice new features introduced in versions 12,13,14, and 15 of the SDK. Fortunately there’s now a third option…

frgaal — Babel for Java

frgaal is a retrofitting compiler for Java based on the OpenJDK version of javac. frgaal can run on Java 8 itself and can produce compatible bytecode for Java versions as old as Java 8.

Usage

Clone the repository:

$ git clone https://github.com/awsdocs/aws-lambda-developer-guide.git
$ cd aws-lambda-developer-guide/sample-apps/java-basic

And create a Bucket for the deployment artifacts:

java-basic$ ./1-create-bucket.sh
make_bucket: lambda-artifacts-a5e4xmplb5b22e0d

Before we build and deploy we’ll modify the the pom.xml. If you open the pom, you’ll find this section:

Replace it with this to use the frgaal compiler:

We’ll also change the code in Handler.java and replace the response with a multiline text block, which were introduced in Java 13:

Deployment

run 2-deploy.sh mvn:

java-basic$ ./2-deploy.sh mvn
[INFO] Scanning for projects...
[INFO] -----------------------< com.example:java-basic >-----------------------
[INFO] Building java-basic-function 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
...

Testing

To do so run the script3-invoke.sh.

java-basic$ ./3-invoke.sh
{
"StatusCode": 200,
"ExecutedVersion": "$LATEST"
}
"200 OK\nLook at this multiline text\n..."

The script will continue invoking the lambda, just pressCRTL+C to exit.

Summary