| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This project creates AWS Lambda Layers with a Java 17 (or newer Version) based on Corretto to allow Lambda Functions to be written using Java 17 or newer.
The pipeline that builds and deploys the runtimes automatically has to be deployed once. This is done by manually deploy the included CDK stack that includes a pipeline. The following command assumes that you have already authenticated to the AWS account and assumed the correct role.
./gradlew clean
./gradlew -PjdkVersion=17 buildLayer # On non-x86_64 machines this may take very long
./gradlew -PjdkVersion=19 buildLayer # On non-x86_64 machines this may take very long
./gradlew :infrastructure:deploy # Deploy the pipeline After deploying the pipeline you have to once approve the Codestar connection to the GitHub repository.
To build the layer locally you need to have Docker installed. Then you can run the following command:
./gradlew -PjdkVersion=17 clean buildLayerThis will build the layer for Java 17. To build the layer for Java 19 replace 17 with 19.
Whenever a new version of the Java runtime is deployed, the ARN of the layer is stored in a SSM parameter named Java<version>RuntimeLayerArn.
To use the custom Java runtime in your application add the following code to your CDK stack:
private ILayerVersion importJavaRuntimeLayer(){
var javaRuntimeLayerArn=StringParameter.valueForStringParameter(this,"Java17RuntimeLayerArn");
return LayerVersion.fromLayerVersionArn(this,"import-JavaLayer",javaRuntimeLayerArn);
}To use the Java 19 runtime replace Java17RuntimeLayerArn with Java19RuntimeLayerArn
var java17Layer=importJavaRuntimeLayer();
Function.Builder.create(this,"Function")
.runtime(Runtime.PROVIDED_AL2)
.architecture(Architecture.X86_64)
// ...
.layers(List.of(java17Layer))
.build();This project uses AWS Lambda Layers to provide a stripped down distribution of Java 17 and 19 Amazon Corretto JDK.
The layer can be shared between all Lambda functions in the account. One important restriction to notice is that the size of all layers and the lambda code itself must not exceed 250MB.
To respect these quotas it's not possible to use the full JDK distribution. Instead this project contains a build script that will create a stripped down JRE of the JDK using jlink. If you are interested in how to do that take a closer look at the Dockerfile.
In addition to the JRE the layer, that is distributed as a ZIP file, contains a bootstrap script that starts the Java runtime and includes the AWS Lambda runtime implementation along with two other dependencies in the classpath and sets the classpath to $LAMBDA_TASK_ROOT, $LAMBDA_TASK_ROOT/*, $LAMBDA_TASK_ROOT/lib/* and /opt/java/lib/*. Please note that Layers are extracted to /opt/ by default. Therefore any other layer that contains dependencies in the java/lib folder of the ZIP archive will become available in the /opt/java/lib folder which is picked-up bey the Lambda runtime.
The infrastructure to build the custom Java runtimes consist of
| Back | FazBrowse Home | New Git URL |