Published Mar 27, 2020
I just wanted to play with Quarkus and AWS Lambda. I did a little proof of concept in one evening. There’s a lot of things to improve of course but it shows that Java has evolved a lot and can start really fast.
This project uses Quarkus, the Supersonic Subatomic Java Framework. If you want to learn more about Quarkus, please visit its website here.
Check the latest version of the quarkus-maven-plugin
on Maven Central - quarkus-maven-plugin
mvn io.quarkus:quarkus-maven-plugin:1.3.0.Final:create \
-DprojectGroupId=com.github.thibaudledent \
-DprojectArtifactId=quarkus-poc \
-DclassName="com.github.thibaudledent.quarkus.poc.HelloResource" \
-Dpath="/quizz"
mvn compile quarkus:dev
curl
curl -X GET "localhost:8080/quizz"
In order to build a native image, you don’t need to have GraalVM configured locally, Quarkus can use a dedicated containerized version of GraalVM for that:
mvn package -Pnative -Dquarkus.native.container-build=true
docker build -f src/main/docker/Dockerfile.native -t thibaudledent/quarkus-poc .
A Docker image is created, you can check its size:
docker images -a | head
It outputs:
REPOSITORY TAG IMAGE ID CREATED SIZE
thibaudledent/quarkus-poc latest d0d0209d1325 13 seconds ago 155MB
docker run thibaudledent/quarkus-poc
Starting time is fast. You can check the startup time with:
time docker run thibaudledent/quarkus-poc
The logs are:
__ ____ __ _____ ___ __ ____ ______
--/ __ \/ / / / _ | / _ \/ //_/ / / / __/
-/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/
2020-03-27 17:23:10,191 INFO [io.quarkus] (main) quarkus-poc 1.0-SNAPSHOT (powered by Quarkus 1.3.0.Final) started in 0.027s. Listening on: http://0.0.0.0:8080
2020-03-27 17:23:10,191 INFO [io.quarkus] (main) Profile prod activated.
2020-03-27 17:23:10,191 INFO [io.quarkus] (main) Installed features: [cdi, resteasy]
^C2020-03-27 17:23:11,081 INFO [io.quarkus] (main) quarkus-poc stopped in 0.005s
docker run thibaudledent/quarkus-poc 0.03s user 0.02s system 3% cpu 1.669 total
docker exec -it $(docker ps | grep thibaudledent | awk '{print $1}') /bin/bash -c "curl -X GET 'localhost:8080/quizz'"
mvn package
java -jar target/quarkus-poc-1.0-SNAPSHOT-runner.jar
Note: This step can be improved by using Quarkus - Amazon Lambda instead.
Upload the jar from target/quarkus-poc-1.0-SNAPSHOT-runner.jar
created with mvn package
:
Use the following as handler:
com.github.thibaudledent.quarkus.poc.HelloResource::hello