An AWS Lambda custom runtime to enable Java 18 support on a minimalistic JRE, which only includes the Java modules required by the application. This is the example repository for the Build a custom Java runtime for AWS Lambda blog post.
- Download the preferred Java version and take advantage of jdeps, jlink and Class Data sharing to create a minified and optimized Java runtime based on the application code (function.jar).
 - Create a bootstrap file with optimized starting instructions for the application.
 - Package the application code, the optimized Java runtime and the bootstrap file as a zip file.
 - Deploy the runtime, including the app, to AWS Lambda e.g. via the AWS Cloud Development Kit (CDK)
 
- 
Download or clone the repository.
 - 
install prerequisite software:
 - 
Build and package the AWS Lambda function and create the AWS Lambda custom runtime using Docker:
 
./build.sh- Provision the AWS infrastructure (Amazon API Gateway, AWS Lambda and Amazon DynamoDB) using AWS CDK:
 
./provision-infrastructure.shThe API Gateway endpoint URL is displayed in the output and saved in the file infrastructure/target/outputs.json. The contents are similar to:
{
  "LambdaCustomRuntimeMinimalJRE18InfrastructureStack": {
    "apiendpoint": "https://<API_ID>.execute-api.<AWS_REGION>.amazonaws.com/prod/"
  }
}
First, install prerequisites:
- Install jq and Artillery Core
 - Run the following script from the projects root directory:
 
artillery run -t $(cat infrastructure/target/outputs.json | jq -r '.LambdaCustomRuntimeMinimalJRE18InfrastructureStack.apiendpoint') -v '{ "url": "/custom-runtime" }' infrastructure/loadtest.yml- Navigate to Amazon CloudWatch Logs Insights.
 - Select the log groups 
/aws/lambda/custom-runtime-java-18from the drop-down list - Copy the following query and choose Run query:
 
 filter @type = "REPORT"
    | parse @log /\d+:\/aws\/lambda\/(?<function>.*)/
    | stats
    count(*) as invocations,
    pct(@duration+coalesce(@initDuration,0), 0) as p0,
    pct(@duration+coalesce(@initDuration,0), 25) as p25,
    pct(@duration+coalesce(@initDuration,0), 50) as p50,
    pct(@duration+coalesce(@initDuration,0), 75) as p75,
    pct(@duration+coalesce(@initDuration,0), 90) as p90,
    pct(@duration+coalesce(@initDuration,0), 95) as p95,
    pct(@duration+coalesce(@initDuration,0), 99) as p99,
    pct(@duration+coalesce(@initDuration,0), 100) as p100
    group by function, ispresent(@initDuration) as coldstart
    | sort by coldstart, function
You see results similar to:
For cold-starts only you will see results similar to:
See CONTRIBUTING for more information.
This library is licensed under the MIT-0 License. See the LICENSE file.



