Maven Archetype for creating minimal Microlam Lambda Pipeline Quickstart project
To use it:
mvn archetype:generate -Dfilter=io.microlam:
- Choose the the number corresponding to 'microlam-lambda-pipeline-quickstart'
- Choose a
groupId
,artifactId
,version
andpackage
. - Choose your
awsBucket
: this is the name of an S3 bucket where the lambda artifacts will be deployed - Choose your
awsProfile
: this is the name of your AWS profile - Choose your
awsRegion
: this is the name of an AWS region (ex:eu-west-1
) - Choose your
lambdaName
: this is the name of your Lambda must be also suitable as the name of the Java class for the Lambda.
There are 2 API endpoints defined in our API via API Gateway:
POST /mult
POST /sum
They are connected to the same lambda via Proxy integration.
Both receive a json body of the form:
{
"arguments" : [ 2, 4, 6]
}
The expected response will be a json of the form:
{
"result" : 12
}
The result will be the sum or the product of the arguments depending on the respective endpoints /sum
or /mult
.
The project will generate a Java 11 lambda and also a Custom Runtime Lambda using GraalVM compilation of the same java code with native-image.
This project implements the Lambda code with the Microlam Pipeline architecture.
mvn package -Pjava
the Java deployment package is in target/
folder with the name [xxx]-aws-lambda.jar
You have 3 options:
- Create the API and the Lambda automatically from the command line using AWS CDK
- Create the API and the Lambda automatically from the command line using AWS SAM
- Create the API and the Lambda manually via the AWS Console
Deploy the App with the CDK:
cdk deploy
Info: if something go wrong, or if you want to clean the AWS Account, you can delete everything related to the project in AWS with the command cdk destroy
Deploy the App with SAM:
sam deploy
Info: if something go wrong, or if you want to clean the AWS Account, you can delete everything related to the project in AWS with the command sam delete
- Using the
profile
,region
andlambdaName
you specified. - Using the Java 11 (Corretto) Lambda Runtime
- Set the handler to
[package].lambda.[lambdaName]
- Create the API in API Gateway as described before in the Project Description
Then Deploy your AWS Lambda Java Deployment Package:
Run the Junit Test in class in
[xxx].devops.UploadAndUpdateLambda
Warning: For this, the pre-requisite is that Docker is installed and running on your machine, if not install it.
-
The native build is depending on the java version (
java11
orjava17
) and the target architecture (amd64
orarm64
). You need to provide this information in maven command line using-Dnative=javaXX-axx64
(by replacing XX and xx with the correct values) -
You need to activate the profile
compile
with-Pcompile
-
If you want the build to pause and allow you to run some tests, use also the profile
dev
:-Pcompile,dev
In case you choose to build from Java 11
targeting amd64
architecture:
mvn clean install -Dnative=java11-amd64 -Pcompile
or with dev mode activated:
mvn clean install -Dnative=java11-amd64 -Pcompile,dev
Excellent! The Native deployment package is in target
folder with the name [xxx]-aws-lambda-native.zip
.
Good ! At the end of the build, a container is running, letting you try your native lambda locally.
It is a good time to run your tests on it:
Run the Junit Tests in class in
[xxx].devops.LocalLambdaTests
If it is working as expected, you are ready to deploy it to AWS!
In another console, while the container is running, launch this command:
mvn docker:copy -Dnative=java11-amd64 -Pcompile
This will copy the Native deployment package to the target
folder with the name [xxx]-aws-lambda-native.zip
.
You can now stop the running container, with CTRL-C and are ready to upload your deployment package to AWS.
See why... it certainly means you need to complete the native-image configuration. see below the instructions for running the container for generating the configuration for you.
You have 3 options:
- Create the API and the Lambda automatically from the command line using AWS CDK
- Create the API and the Lambda automatically from the command line using AWS SAM
- Create the API and the Lambda manually via the AWS Console
You need to apply a few changes to the class [xxx].devops.cdk.CreateApp
(from src/test
folder), to set the function Runtime, Architecture and Code.
Deploy the App with the CDK:
cdk deploy
Deploy the App with SAM:
sam deploy --template template-native.yaml
Info: if something go wrong, or if you want to clean the AWS Account, you can delete everything related to the project in AWS with the command sam delete
- Using the
profile
,region
and[lambdaName]Native
you specified. - Using the 'Custom runtime on Amazon Linux 2' Lambda Runtime
- Set the handler to
[package].lambda.[lambdaName]
Then Deploy your AWS Lambda Native Deployment Package
Run the Junit Test in in class in
xxx.devops.UploadAndUpdateLambdaNative
mvn clean install -Dnative=java11-amd64 -Pconfig
At the end of the build, a container is running, letting you try your Java lambda locally with the GraalVM Tracing Agent.
It is a good time to run your tests on it :
Run the Junit Tests in class in
[xxx].devops.LocalLambdaTests
The generated configuration is updated every 30s in folder: src/main/resources/META-INF/native-image/[groupId]/[artifactId]/
.
If necessary, update the file native-image.properties
, stop the running container with CTRL-C and retry to compile.