---
title: How to deploy a Quarkus Lambda Application using Lambda Containers
description: This step-by-step demo explains in detail how to deploy a Quarkus Lambda Application using Lambda Containers on AWS. | How-to tech post | Code Sample
---

[Secure SaaS Delivery, Cloud & DevOps | base2Services](https://blog.base2services.com)

# [How to deploy a Quarkus Lambda Application using Lambda Containers](https://blog.base2services.com/how-to-deploy-a-quarkus-lambda-application-using-lambda-containers)

 Written by [Aaron Walker](https://blog.base2services.com/author/aaron-walker) | Mar 4, 2023, 7:42:00 AM

*This post was originally published on [my personal blog](https://aaronwalker.cloud/2020/12/04/quarkus-lambda-containers.html)*

At re:Invent 2020 Amazon announced support for deploying and running containers directly to Lambda. Here is a link to the blog post for the announcement [https://aws.amazon.com/blogs/aws/new-for-aws-lambda-container-image-support/](https://aws.amazon.com/blogs/aws/new-for-aws-lambda-container-image-support/).

Recently, I've been messing around with [Quarkus](https://quarkus.io/) which is a relatively new Java framework for building Apps and already has a pretty impressive eco-system.

This demo shows how you can package a Quarkus Lambda App using the new [Lambda containers](https://docs.aws.amazon.com/lambda/latest/dg/lambda-images.html) support. I basically used the Quarkus - Amazon Lambda guide as the basis for this demo.

## TL;DR

The code for this demo is available on GitHub [https://github.com/base2Services/quarkus-lambda-container-demo](https://github.com/base2Services/quarkus-lambda-container-demo)

## Prerequisites

To complete this guide, you need:

- less than 30 minutes
- JDK 11 (AWS requires JDK 1.8 or 11)
- Apache Maven 3.6.2+
- An Amazon AWS account
- AWS CLI
- Docker

So lets get started.

## Creating the Maven Deployment Project

First, we are going to create a basic Quarkus Lambda app using the Maven archetype.

These steps are taken from the [Quarkus Lambda guide](https://quarkus.io/guides/amazon-lambda#creating-the-maven-deployment-project).

```
mvn archetype:generate \       -DarchetypeGroupId=io.quarkus \       -DarchetypeArtifactId=quarkus-amazon-lambda-archetype \       -DarchetypeVersion=1.10.2.Final
```

This will create a standard Quarkus Lambda app in a directory based on the Maven artifactId you entered. I will use `quarkus-lambda-demo` for the rest of the guide.

This generates a simple Quarkus Lambda application with a Test Lambda handler.

```
package com.base2services;import javax.inject.Inject;import javax.inject.Named;import com.amazonaws.services.lambda.runtime.Context;import com.amazonaws.services.lambda.runtime.RequestHandler;@Named("test")public class TestLambda implements RequestHandler<InputObject, OutputObject> {    @Inject    ProcessingService service;    @Override    public OutputObject handleRequest(InputObject input, Context context) {        return service.process(input).setRequestId(context.getAwsRequestId());    }}
```

 

### Add the AWS Lambda Runtime Emulator Dependency

Add the following dependency to the Maven pom dependencies.

```
....<dependency>    <groupId>com.amazonaws</groupId>    <artifactId>aws-lambda-java-runtime-interface-client</artifactId>    <version>1.0.0</version></dependency>....
```

 

## Build the demo

In the quarkus-lambda-demo run Maven.

```
$ mvn clean install...INFO] --- maven-install-plugin:2.4:install (default-install) @ quarkus-lambda-demo ---[INFO] Installing /Users/aaronwalker/Workspaces/aaronwalker/quarkus-lambda-container-demo/quarkus-lambda-demo/target/quarkus-lambda-demo-1.0-SNAPSHOT.jar to /Users/aaronwalker/.m2/repository/com/base2services/quarkus-lambda-demo/1.0-SNAPSHOT/quarkus-lambda-demo-1.0-SNAPSHOT.jar[INFO] Installing /Users/aaronwalker/Workspaces/aaronwalker/quarkus-lambda-container-demo/quarkus-lambda-demo/pom.xml to /Users/aaronwalker/.m2/repository/com/base2services/quarkus-lambda-demo/1.0-SNAPSHOT/quarkus-lambda-demo-1.0-SNAPSHOT.pom[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time:  13.732 s[INFO] Finished at: 2020-12-03T15:10:39+01:00
```

 

This will create the required artifacts in the target directory.

## Lambda Function

The quarkus-lambda-demo project has by default configured the test handler in the `quarkus-lambda-demo/src/main/resources/application.properties/` and we will use this handler for the demo.

```
quarkus.lambda.handler=test
```

 

## Building the Dockerfile

Create a Dockerfile in the quarkus-lambda-container-demo using the `public.ecr.aws/lambda/java:8.al2` Lambda java8 Amazon Linux 2 runtime container as the base image.

```
# (1)FROM  public.ecr.aws/lambda/java:8.al2ARG APP_NAME=quarkus-lambda-demoARG APP_VERSION=1.0-SNAPSHOT# (2) Copies artifacts into /function directoryADD ${APP_NAME}/target/${APP_NAME}-${APP_VERSION}-runner.jar /var/task/lib/${APP_NAME}.jarADD ${APP_NAME}/target/lib/  /var/task/lib/# (3) Setting the command to the Quarkus lambda handlerCMD ["io.quarkus.amazon.lambda.runtime.QuarkusStreamHandler::handleRequest"]
```

 

1\) Details about the Lambda container images can be found at [https://docs.aws.amazon.com/lambda/latest/dg/images-create.html](https://docs.aws.amazon.com/lambda/latest/dg/images-create.html)

2\) Copies the runner and its dependencies into the default WORKDIR which is /var/task

3\) Overrides the CMD using the default Quarkus Lambda handler

### Then build the Docker image

```
$ docker build -t quarkus/lambda-demo .....Successfully built 09666b8a56b0Successfully tagged quarkus/lambda-demo:latest
```

 

### Testing local using Docker

You can now use this image to test the Lambda execution locally using:

```
$ docker run --rm -it -p 9000:8080 quarkus/lambda-demo:latest....INFO[0000] exec '/var/runtime/bootstrap' (cwd=/var/task, handler=)....
```

 

This starts the AWS Lambda runtime emulator and a web server listening locally on port 9000. You can invoke the test Lambda handler using curl.

```
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"greeting":"herzlich willkommen", "name":"aaron"}'....{"result":"herzlich willkommen aaron","requestId":"d8a48f84-a166-429e-a8ec-d8bea2e7087c"}
```

 

## Push the container to ECR

In order to be able to create a Lambda function from our container image we need to push it to a registry. I will use ECR in the guide.

Assumes you have valid AWS credentials configured

### Create the ECR registry

```
$ aws ecr create-repository --repository-name quarkus/lambda-demo --region eu-central-1....{    "repository": {        "repositoryArn": "arn:aws:ecr:eu-central-1:<aws-accountid>:repository/quarkus/lambda-demo",        "registryId": "<aws-accountid>",        "repositoryName": "quarkus/lambda-demo",        "repositoryUri": "<aws-accountid>.dkr.ecr.eu-central-1.amazonaws.com/quarkus/lambda-demo",        "createdAt": "2020-12-03T16:10:37+01:00",        "imageTagMutability": "MUTABLE",        "imageScanningConfiguration": {            "scanOnPush": false        },        "encryptionConfiguration": {            "encryptionType": "AES256"        }
```

 

### Tag and push the container image to ECR

```
$ aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin <aws-accountid>.dkr.ecr.eu-central-1.amazonaws.com$ docker tag quarkus/lambda-demo  <aws-accountid>.dkr.ecr.eu-central-1.amazonaws.com/quarkus/lambda-demo$ docker push <aws-accountid>.dkr.ecr.eu-central-1.amazonaws.com/quarkus/lambda-demo....The push refers to repository [<aws-accountid>.dkr.ecr.eu-central-1.amazonaws.com/quarkus/lambda-demo]
```

 

### Create the Lambda function

Create a SAM template to deploy the function.

**sam.container.yaml**

```
AWSTemplateFormatVersion: '2010-09-09'Transform: AWS::Serverless-2016-10-31Description: AWS Serverless Quarkus - quarkus-lambda-demo-1.0-SNAPSHOTParameters:  ImageUri:    Type: StringResources:  QuarkusLambdaDemo:    Type: AWS::Serverless::Function    Properties:      PackageType: Image      ImageUri: !Ref ImageUri      MemorySize: 256      Timeout: 15      Policies: AWSLambdaBasicExecutionRoleOutputs:  Function:    Value: !Ref QuarkusLambdaDemo
```

 

Now deploy the template.

```
AWS_REGION=eu-central-1AWS_ACCOUNT_ID=xxxxxx$ aws cloudformation deploy \  --stack-name quarkus-lambda-demo \  --template-file sam.container.yaml \  --parameter-overrides ImageUri=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/quarkus/lambda-demo:latest \  --capabilities CAPABILITY_IAM \  --region ${AWS_REGION}
```

 

Now invoke the function.

```
$ aws lambda invoke \    --cli-binary-format raw-in-base64-out \    --function-name QuarkusLambdaDemo \    --payload '{"greeting":"herzlich willkommen", "name":"aaron"}' \    --region ${AWS_REGION}    out.json{    "StatusCode": 200,    "ExecutedVersion": "$LATEST"}$ cat out.json{"result":"herzlich willkommen aaron","requestId":"02d6569d-0452-4ed7-bdbe-7e860a8592d8"}
```

 

## Summary

Without much modification it was possible to create a simple Quarkus Lambda App and package it as a container image. Quarkus gives you the ability to run the app locally. However, by running it in the container, it gives you the same environment that the app will run in when deployed to Lambda. Another big advantage of using a container is that you aren't restricted by the Lambda zip file size limit.

Follow me on [Twitter](https://twitter.com/aaronwalker) for regular updates and my random thoughts on various topics. If you have questions or remarks, or would just like to get in touch, you can also find me on [LinkedIn](https://www.linkedin.com/in/aaronpwalker/).

[View full post](https://blog.base2services.com/how-to-deploy-a-quarkus-lambda-application-using-lambda-containers)

```json
{
  "@context" : "http://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Aaron Walker"
  },
  "dateModified" : "2023-09-18T12:02:40.046Z",
  "datePublished" : "2023-03-04T07:42:00Z",
  "headline" : "How to deploy a Quarkus Lambda Application using Lambda Containers",
  "image" : {
    "@type" : "ImageObject",
    "height" : 400,
    "url" : "https://5667837.fs1.hubspotusercontent-na1.net/hubfs/5667837/quarkus-lambda-containers-1.jpg",
    "width" : 600
  },
  "mainEntityOfPage" : "https://blog.base2services.com/how-to-deploy-a-quarkus-lambda-application-using-lambda-containers",
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "height" : 60,
      "url" : "/hs/hsstatic/content_shared_assets/static-1.4092/img/default-amp-logo.png",
      "width" : 60
    },
    "name" : "Secure SaaS Delivery, Cloud & DevOps | base2Services"
  }
}
```