AWS Lambda with Quarkus on Gitlab CI/CD

AWS Lambda with Quarkus on Gitlab CI/CD

The quarkus-amazon-lambda extension allows you to use Quarkus to build your AWS Lambdas. Your Lambdas can use injection annotations from CDI or Spring and other Quarkus facilities as you need them.

Quarkus Lambdas can be deployed using the Amazon Java Runtime, or you can build a native executable and use Amazon’s Custom Runtime if you want a smaller memory footprint and faster cold boot startup time. You can follow the video or continue reading.


Create the sample project

We use the quarkus-amazon-lambda-archetype to create our sample maven project. Give the project a artifactId of quarkus-lambda-gitlab.

mvn archetype:generate -DarchetypeGroupId=io.quarkus -DarchetypeArtifactId=quarkus-amazon-lambda-archetype -DarchetypeVersion=1.8.0.Final

cd quarkus-lambda-gitlab

# remove gradle files
rm build.gradle settings.gradle

Create Gitlab project

Go to login with your account. Create new project. Name it quarkus-lambda-gitlab. Change to your local maven project and enter:

git init
git remote add origin
git add .
git commit -m "Initial commit"
git push -u origin master

Prepare project for Gitlab maven repository

Change jdk version in pom.xml from 1.8 to 11


Add a new file in the root of your project named with this line:


Add this line to the src/main/resources/ file


Create a personal access token

Follow this instructions to create a personal access token with the api scope.

Add the token to your maven settings.xml file. The file should be in your $HOME/.m2 directory. If not, create the file.


Add the repository settings to your pom.xml. Change the PROJECT_ID with your project id which you find on your project overview page in Gitlab.


Add the assembly plugin to the pom.xml


And the assembly descriptor to src/main/assembly/assembly.xml. This will add the native Quarkus binary to a zip file.

<assembly xmlns=""

Deploy the project

To deploy the project to the Gitlab maven repository enter:

 mvn clean deploy -Pnative -Dquarkus.native.container-build=true

After the last command finished successfully the Lambda function is zipped and deployed to the maven repository.

Prepare CI pipeline

Create a ci_settings.xml file in your project root directory with this content

<settings xmlns="" xmlns:xsi=""

Add a shell script named to your project root directory with this content

#!/usr/bin/env bash

echo "Downloading GraalVM"
curl -L > graalvm-ce-java11-linux-amd64-20.1.0.tar.gz
tar -zxf graalvm-ce-java11-linux-amd64-20.1.0.tar.gz -C ${CI_PROJECT_DIR}/
ls -la

echo "Installing GraalVM via gu"

${CI_PROJECT_DIR}/graalvm-ce-java11-20.1.0/bin/gu install native-image

Add a pipeline script named .gitlab-ci.yml to your project root directory with this content

image: maven:3.6.3-openjdk-11-slim

  # This will supress any download for dependencies and plugins or upload messages which would clutter the console log.
  # `showDateTime` will show the passed time in milliseconds. You need to specify `--batch-mode` to make this work.
  MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
  # As of Maven 3.3.0 instead of this you may define these options in `.mvn/maven.config` so the same config is used
  # when running from the command line.
  # `installAtEnd` and `deployAtEnd` are only effective with recent version of the corresponding plugins.
  MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"

    - .m2/repository

  - build
  - release
  - deploy

  - echo " ------------------------------- Global > Before Script -------------------------------"
  - apt-get update -qq
  - apt-get install -y -qq build-essential libz-dev zlib1g-dev

  stage: build
    - chmod +x && ./ jdk11
    - export GRAALVM_HOME=${CI_PROJECT_DIR}/graalvm-ce-java11-20.1.0
    - mvn clean deploy -s ci_settings.xml -P native
    - master

Commit and push all changes. After some minutes you should have the Lambda function code built and zipped in your Gitlab maven repository.


In this post we used Quarkus to build a Lambda function with custom runtime. The advantage of this is a fast startup and execution time of the Lambda function. We built a CI pipeline using Gitlab. In the next part we will deploy this Lambda function with help of terraform.

comments powered by Disqus