This project uses the following framework
- Quarkus - The Supersonic Subatomic Java Framework for building Cloud Native Applications
- Apache Camel - The Swiss Army Knife of Enterprise Application Integration for integrating heterogeneous systems
- AWS Lambda - Event-driven, serverless computing platform provided by Amazon as a part of Amazon Web Services
If you want to learn more about
- Quarkus - please visit its website: https://quarkus.io/
- Apache Camel - please visit its website: https://camel.apache.org/
- AWS Lambda - please visit its website: https://aws.amazon.com/lambda/
This example contains a sample Greeter service build using Quarkus & Camel which can be deployed into the Amazon Lambda as function.
⚠️ INCOMPATIBLE WITH DEV MODE: Amazon Lambda Binding is not compatible with dev mode yet!
You can run your application in dev mode that enables live coding using:
./mvnw compile quarkus:dev
NOTE: Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/.
The application can be packaged using:
./mvnw clean package
This will compile and package your code.
It produces the quarkus-run.jar
file in the target/quarkus-app/
directory.
Be aware that it’s not an uber-jar as the dependencies are copied into the target/quarkus-app/lib/
directory.
If you want to build an uber-jar, execute the following command:
./mvnw package -Dquarkus.package.type=uber-jar
The application is now runnable using java -jar target/quarkus-app/quarkus-run.jar
.
It also generates a zip file target/function.zip. This zip file contains your java code along with the dependencies.
If you want a lower memory footprint and faster initialization times for your lambda, you can compile your Java code to a native executable. Just make sure to rebuild your project with the -Pnative switch.
./mvnw package -Pnative
ℹ️ If you are building on a non-Linux system Or, if you don't have GraalVM installed, you can run the native executable build using docker container. You need to pass in a property instructing quarkus to use a docker build as Amazon Lambda requires linux binaries. You can do this by passing this property to your Maven build:
-Dquarkus.native.container-build=true
. However, This requires to have docker installed locally.
./mvnw package -Pnative -Dquarkus.native.container-build=true
Either of these commands will compile and create a native executable image.
You can then execute your native executable with: ./target/code-with-quarkus-1.0.0-SNAPSHOT-runner
It also generates a zip file target/function.zip. This zip file contains your native executable image renamed to bootstrap. This is a requirement of the AWS Lambda Custom (Provided) Runtime.
If you want to learn more about building native executables, please consult https://quarkus.io/guides/maven-tooling.html.
NOTE: After you run the build, there are a few extra files generated by the quarkus-amazon-lambda extension. These files are in the build directory: target/
-
function.zip - lambda deployment file
-
manage.sh - wrapper around aws lambda cli calls
-
bootstrap-example.sh - example bootstrap script for native deployments
-
sam.jvm.yaml - (optional) for use with sam cli and local testing
-
sam.native.yaml - (optional) for use with sam cli and native local testing
ℹ️ Please click here for details on how to use these scripts
-
Go to AWS Web console and search for Lambda Service
-
Click Create Function and select Author From Scratch
-
Give the name for your function which should be unique
-
Select Java 11 (Corretto) as Runtime
-
Under Permission feel free to create / use existing role to give the required permission for your lambda function
-
Once the function is created click the function name to upload and configure it.
-
Scroll down and select the Code tab. Click the upload from dropdown on right hand side of the screen and select .zip or .jar file
-
Click upload and browse to the path where the generated a zip file is created
target/function.zip
and select the function.zip file and click save -
Under the Code tab scroll down to the Runtime settings and click edit
-
For the Handler details please provide the Quarkus Handler
io.quarkus.amazon.lambda.runtime.QuarkusStreamHandler::handleRequest
-
Now select the Test tab for executing a quick test. Copy paste the below json payload and hit Test
{ "name": "Ravishankar" }
-
If everything goes fine you should get the below response along with the lambda execution logs & stats
Hello Ravishankar ! How are you? from GreetService
NOTE: Please ensure that you have built your Java code as Quarkus Native executable
-
Go to AWS Web console and search for Lambda Service
-
Click Create Function and select Author From Scratch
-
Give the name for your function which should be unique
-
For Runtime please scroll down and Select Provide your own bootstrap on Amazon Linux 2 under Custom Runtime
-
Under Permission feel free to create / use existing role to give the required permission for your lambda function
-
Once the function is created click the function name to upload and configure it.
-
Scroll down and select the Code tab. Click the upload from dropdown on right hand side of the screen and select .zip or .jar file
-
Click upload and browse to the path where the generated a zip file is created
target/function.zip
and select the function.zip file and click save -
Under the Code tab scroll down to the Runtime settings and click edit
-
For the Handler details please provide the below Handler
not.used.in.provided.runtime
-
Then Select the Configuration tab and click Environment Variables
-
For Key enter
DISABLE_SIGNAL_HANDLERS
& for Value entertrue
-
Now select the Test tab for executing a quick test. Copy paste the below json payload and hit Test
{ "name": "Ravishankar" }
-
If everything goes fine you should get the below response along with the lambda execution logs & stats
Hello Ravishankar ! How are you? from GreetService