Git Product home page Git Product logo

aws-lambda-java-base-images's Introduction

AWS Lambda Java Base Images

This project provides the missing AWS Lambda base image for Java 17, 18, 19, 20, and 21. The base images are publicly available in the ECR Public Gallery. You should be able to use them directly in your builds. I use these images in production for personal and commercial projects today, but per the license, there is no warranty, and YMMV.

Approach

This project uses the following process to create new Lambda base images:

  1. Define a Java maven POM that includes all the Java Lambda support libraries as provided scope. This roundabout approach is used to coax @dependabot into flagging new versions as they are published.
  2. Also teach maven to collect these dependencies and build the appropriate docker images using a Dockerfile and the excellent fabric8io/docker-maven-plugin.
  3. Use GitHub Actions to perform CI/CD and release new images to the ECR Public Gallery.

Example Lambda Function

You can find an example Lambda function using these base images at aleph0io/example-java-lambda-function. It's just like building any container lambda function. For ease of use, find the Dockerfile below. Note the FROM image. Java versions 17-20 are also supported.

FROM public.ecr.aws/aleph0io/java/lambda:21-al2

COPY target/hello-lambda.jar "${LAMBDA_TASK_ROOT}/lib/"

CMD [ "com.sigpwned.lambda.hello.HelloLambda::handleRequest" ]

Testing Lambda Functions Locally

The Lambda RIE is not currently built into these lambda base images, so to test your lambda function implementations locally, you will need to use the standalone RIE server.

Known Issues and Future Plans

  • This image is in no way optimized for cold start time, size, etc. PRs welcome!
  • Java 17, 18, 19, 20, and 21 are all supported.
  • For now, only x86_64 is supported. I hope to publish multiarch builds including arm64 soon.
  • Official base images for Java 17 have been released to lambda/java. Java 17 users should strongly consider moving to the officially-supported base images. This project will continue to release updates for Java 17 on an ongoing basis for those who prefer not to move.
  • This project will continue to support non-LTS Java versions that will never receive an officially-supported AWS Lambda base image.

More Information

You can find writeups of the Java 17, 18, 19, 20, and 21 on my blog.

Acknowledgements

Many thanks to @rieckpil for his outstanding writeup of custom Lambda runtimes. That tutorial was the foundation and basis for this build. Cheers!

Also, thank you to @msailes for the example Java 17 Lambda layer. This prior art was also critically important to understanding how best to integrate a new Java version into Lambda.

Managed by @sigpwned.

aws-lambda-java-base-images's People

Contributors

dependabot[bot] avatar sigpwned avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

aws-lambda-java-base-images's Issues

Add support for slim-alpine corretto images that are smaller and simpler

The current images use the amazon linux 2 based corretto images. It would be nice to use the smaller images since I don't require full amazon linux in my lambda images.

It might be nice to also support slim-al2 as well at the same time for others that want al2.

Thanks for this great repo!

Could not get environment variable AWS_LAMBDA_RUNTIME_API

When I create and run the Docker image locally, I get the following error

Could not get environment variable AWS_LAMBDA_RUNTIME_API

When I host it on the Lambda and test, it shows the following error

Error: fork/exec /lambda-entrypoint.sh: exec format error Runtime.InvalidEntrypoint

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.