Skip to content

Commit 83b6ea2

Browse files
author
Vadym Kazulkin
committed
add aws lambda container mage with java21
1 parent 78e8419 commit 83b6ea2

File tree

2 files changed

+32
-29
lines changed

2 files changed

+32
-29
lines changed

README.md

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Explore ways to run Spring Boot application with AWS Lambda Java or Customer Runtime with GraalVM Native Image
1+
# Explore ways to run Serverless application on AWS Lambda with Java 21 based Docker Container Image
22

33
## Architecture
44

@@ -9,12 +9,6 @@
99
## Project Description
1010
The code example include storing and retrieving product from the Amazon DynamoDB. I put Amazon API Gateway in front of my Lambdas.
1111

12-
I explore the following ways to run Spring Boot application with AWS Lambda Java or Customer Runtime with GraalVM Native Image:
13-
14-
- Lambda with Java 21 Runtime and Spring Boot 3.2 and aws-serverless-java-container
15-
- Lambda with Java 21 Runtime and Spring Boot 3.2 and Spring Cloud Function
16-
- Lambda with Java 21 Runtime and Spring Boot 3.2 and Lambda Web Adapter
17-
- Lambda with Custom Runtime and Spring Boot 3.2 and GraalVM Native Image
1812

1913

2014
I made all the test for the following use cases:
@@ -27,28 +21,45 @@ I made all the test for the following use cases:
2721

2822
# Installation and deployment
2923

24+
Install Java Coretto 21 (https://docs.aws.amazon.com/corretto/latest/corretto-21-ug/amazon-linux-install.html
25+
26+
sudo yum install java-21-amazon-corretto
27+
28+
Install Maven
29+
30+
wget https://mirrors.estointernet.in/apache/maven/maven-3/3.8.5/binaries/apache-maven-3.8.5-bin.tar.gz
31+
tar -xvf apache-maven-3.8.5-bin.tar.gz
32+
sudo mv apache-maven-3.8.5 /opt/
33+
34+
35+
M2_HOME='/opt/apache-maven-3.8.5'
36+
PATH="$M2_HOME/bin:$PATH"
37+
export PATH
38+
39+
40+
41+
3042
```bash
3143

3244
Clone git repository locally
33-
git clone https://github.com/Vadym79/AWSLambdaJavaWithSpringBoot.git
45+
git clone https://github.com/Vadym79/AWSLambdaJavaDockerImage.git
3446

3547
Compile and package the Java application with Maven from the root (where pom.xml is located) of the project
36-
mvn clean package
48+
mvn compile dependency:copy-dependencies -DincludeScope=runtime
3749

38-
Deploy your application with AWS SAM
39-
sam deploy -g
40-
```
50+
docker build -t aws-pure-lambda-java21-custom-docker-image:v1 .
51+
docker save aws-pure-lambda-java21-custom-docker-image > aws-pure-lambda-java21-custom-docker-image
4152

42-
In order not to use AWS Lambda SnapStart comment both lines in the globals's section of the Lambda function.
53+
aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin {aws_account_id}.dkr.ecr.eu-central-1.amazonaws.com
4354

44-
Globals:
45-
Function:
46-
#SnapStart:
47-
#ApplyOn: PublishedVersions
55+
aws ecr create-repository --repository-name aws-pure-lambda-java21-custom-docker-image --image-scanning-configuration scanOnPush=true --region eu-central-1
4856

49-
In order to user AWS Lambda SnapStart uncomment both lines above. For different Priming optimizations enabling of SnapStart is required.
50-
SnapStart doesn't currently work for AWS Custom Runtimes, so for GraalVM Native Image.
57+
docker tag aws-pure-lambda-java21-custom-docker-image:v1 265634257610.dkr.ecr.eu-central-1.amazonaws.com/aws-pure-lambda-java21-custom-docker-image:v1
5158

59+
docker push 265634257610.dkr.ecr.eu-central-1.amazonaws.com/aws-pure-lambda-java21-custom-docker-image:v1
60+
Deploy your application with AWS SAM
61+
sam deploy --image-repository=${ecr_image_reposiory} -g
62+
```
5263

5364
## Further Readings
5465

pure-lambda-java-21-docker-image/template.yaml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,10 @@ Resources:
9090

9191
GetProductByIdFunction:
9292
Type: AWS::Serverless::Function
93-
Metadata:
94-
DockerTag: v1
95-
DockerContext: .
96-
Dockerfile: ./Dockerfile
9793
Properties:
9894
FunctionName: GetProductByIdWithPureJava21DockerImage
99-
#Handler: software.amazonaws.example.product.handler.GetProductByIdHandler::handleRequest
10095
PackageType: Image
96+
ImageUri: !Sub ${AWS::AccountId}.dkr.ecr.eu-central-1.amazonaws.com/aws-pure-lambda-java21-custom-docker-image:v1
10197
ImageConfig:
10298
Command: ["software.amazonaws.example.product.handler.GetProductByIdHandler::handleRequest"]
10399
Policies:
@@ -121,14 +117,10 @@ Resources:
121117

122118
PutProductFunction:
123119
Type: AWS::Serverless::Function
124-
Metadata:
125-
DockerTag: v1
126-
DockerContext: .
127-
Dockerfile: ./Dockerfile
128120
Properties:
129121
FunctionName: PutProductWithPureJava21DockerImage
130-
#Handler: software.amazonaws.example.product.handler.CreateProductHandler::handleRequest
131122
PackageType: Image
123+
ImageUri: !Sub ${AWS::AccountId}.dkr.ecr.eu-central-1.amazonaws.com/aws-pure-lambda-java21-custom-docker-image:v1
132124
ImageConfig:
133125
Command: ["software.amazonaws.example.product.handler.CreateProductHandler::handleRequest"]
134126

0 commit comments

Comments
 (0)