AWS Java Lambda Generator

The project generated using OpenLegacy's Java Lambda generator supports all possible deployment options for the AWS Lambda environment:

  1. A single uber-jar (with the suffix "-all.jar" in its name) file that includes all the dependencies (if the size of the final .jar doesn't exceed the Lambda limits, the user must manually deploy it using the AWS CLI or web interface);
  2. A standard small .jar file along with a Lambda-layer zip file that contains all the dependency .jar files (the deployment scripts use this approach as it is sufficient for most use cases, but the user could also deploy it manually);
  3. A Dockerfile for creating a Lambda Docker image (the user needs to deploy it to the Amazon ECR manually).

Deploying using a single .jar file

The OpenLegacy Java AWS Lambda project could be deployed as a single uber-jar (with the suffix "-all.jar" in its name) file that includes all the dependencies (if the size of the final .jar doesn't exceed the Lambda limits of 256 Megabytes).

The user must manually deploy it using the AWS CLI or web interface.


Deploying using Lambda Layers

For the user’s convenience, the Java AWS Lambda generator now automatically generates additional scripts in the ./scripts directory for the deployment and un-deployment which create and manage layers for the user. These scripts utilize the AWS CLI to interact with the AWS environment. The user must install and configure it properly before using the provided scripts.

If the provided scripts are not suitable for the user, the Lambda layer could be created manually from the generated .zip file following the official manual - https://docs.aws.amazon.com/lambda/latest/dg/java-layers.html#java-layer-creating


Docker Image

As an alternative to the layers approach, the Java AWS Lambda generator also generates a Dockerfile and ./scripts/docker-build.sh script, so the user can deploy the project as the Docker image to the AWS Lambda environment. This could be done by following the official guide - https://docs.aws.amazon.com/lambda/latest/dg/java-image.html

The /scripts/docker-build.sh takes two optional parameters - the Docker image name and version. By default, they have the following values: HUB project name, latest.

This script will build the project and the Docker image, and print out the information about the built image and how to test it locally:

Docker image built successfully.
To run the Docker image, execute the following command:
docker run -p 9000:8080 as400-cobol-mf-cics:latest [Java Handler Fully Qualified Class Name (io.ol.ProjectHandler)]
To invoke the Lambda function, execute the following command:
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"payload":"{}"}'

To test the built Docker image locally, you need to provide the Lambda handler class as a parameter for the following command:

docker run -p 9000:8080 as400-cobol-mf-cics:latest io.ol.ProjectHandler

This Docker image is built based on the official AWS Lambda image public.ecr.aws/lambda/java:17, and it exposes the following endpoint to trigger the Lambda function - http://localhost:9000/2015-03-31/functions/function/invocations which accepts only POST requests:

curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"payload":"{}"}'

How to use the new scripts:


DescriptionExample
Builds the project without executing the unit tests./scripts/build.sh
Builds the project with executing the unit tests. This is an optional parameter../scripts/build.sh test
Prints the help message with a description of all required and optional parameters./scripts/deploy.sh
Builds and deploys the Lambda to the specified AWS Account ID, Lambda name, Lambda handler class, and uploads it to the S3 bucket. Only required parameters.

The Lambda role name is being constructed following the pattern "${lambda-name}-role". The default Lambda function memory size is 512.
./scripts/deploy.sh <AWS Account ID> <Lambda name> io.ol.ProjectHandler <S3 bucket>
Builds and deploys the Lambda to the specified AWS Account ID, Lambda name, Lambda handler class, and uploads it to the S3 bucket with a custom Lambda role name and configures a Lambda function to use the specified memory size../scripts/deploy.sh <AWS Account ID> <Lambda name> io.ol.ProjectHandler <S3 bucket> <custom-lambda-role> <Memory Size>
Prints the help message with a description of all required and optional parameters./scripts/undeploy.sh
Un-deploys and deletes the deployed Lambda function from the AWS Account by its name. Also deletes all its related resources (layer, role, and files from the S3 bucket).
Only required parameters.
The Lambda role name is being constructed following the pattern "${lambda-name}-role". The default Lambda function memory size is 512.
./scripts/undeploy.sh <AWS Account ID> <Lambda name> io.ol.ProjectHandler <S3 bucket>
Un-deploys and deletes the deployed Lambda function from the AWS Account by its name. Also deletes all its related resources (layer, role, and files from the S3 bucket). Allows specifying the custom Lambda role name../scripts/undeploy.sh <AWS Account ID> <Lambda name> io.ol.ProjectHandler <S3 bucket> <custom-lambda-role>