Deploy Java Lambda functions with container images
You can deploy your Lambda function code as a container image. AWS provides the following resources to help you build a container image for your Java function:
-
AWS base images for Lambda
These base images are preloaded with a language runtime and other components that are required to run the image on Lambda. AWS provides a Dockerfile for each of the base images to help with building your container image.
-
Open-source runtime interface clients (RIC)
If you use a community or private enterprise base image, you must add a Runtime interface client to the base image to make it compatible with Lambda.
-
Open-source runtime interface emulator (RIE)
Lambda provides a runtime interface emulator for you to test your function locally. The base images for Lambda and base images for custom runtimes include the RIE. For other base images, you can download the RIE for testing your image locally.
The workflow for a function defined as a container image includes these steps:
-
Build your container image using the resources listed in this topic.
-
Upload the image to your Amazon ECR container registry.
-
Create the Lambda function or update the function code to deploy the image to an existing function.
Topics
AWS base images for Java
AWS provides the following base images for Java:
Tags | Runtime | Operating system | Dockerfile | Deprecation |
---|---|---|---|---|
11 |
Java 11 | Amazon Linux 2 | Dockerfile
for Java 11 on GitHub |
|
8.al2 |
Java 8 | Amazon Linux 2 | Dockerfile
for Java 8 on GitHub |
|
8 |
Java 8 | Amazon Linux | Dockerfile
for Java 8 on GitHub |
Amazon ECR repository: gallery.ecr.aws/lambda/java
Using a Java base image
For instructions on how to use a Java base image, choose the usage tab on Lambda base images for Java
Java runtime interface clients
Install the runtime interface client for Java using the Apache Maven package manager. Add the following to
your pom.xml
file:
<dependency> <groupId>com.amazonaws</groupId> <artifactId>aws-lambda-java-runtime-interface-client</artifactId> <version>1.0.0</version> </dependency>
For package details, see Lambda RIC
You can also view the Java client source code in the AWS Lambda Java Support Libraries
After your container image resides in the Amazon ECR container registry, you can create and run the Lambda function.
Deploy the container image
For a new function, you deploy the Java image when you create the function. For an existing function, if you rebuild the container image, you need to redeploy the image by updating the function code.