DEV Community

Ed Legaspi
Ed Legaspi

Posted on • Updated on • Originally published at czetsuyatech.com

How to Deploy a Quarkus RESTEasy Microservice as AWS Lambda Function

1. Introduction

In this article, we will learn how to deploy a RESTEasy microservice in Quarkus as AWS Lambda function.

2. What is AWS Lambda?

AWS Lambda is a serverless computing platform commonly used to perform an event-driven function. But with the recent updates, it can also be used to handle HTTP and REST requests. This entails a large saving in cloud usage fees compared to other services where containers can be run like AWS Fargate and EC2. Especially if the service is not in use 24/7.

3. What is Quarkus?

Quarkus is another Java framework similar to Spring but optimized to make it more efficient for containers, cloud, and serverless environments. It also provides a library quarkus-amazon-lambda-rest that is used to deploy a RESTEasy (JAX-RS) microservice as a Lambda function using AWS Gateway REST API.

4. What do you need to Create a Quarkus Project?

You can use the project starter creator available at: https://code.quarkus.io.

Or use the Quarkus plugin in IntelliJ or Eclipse to create a Quarkus project template.

Image description

Quarkus project in IntelliJ.

5. What do you need to Deploy a Quarkus Lambda Function on AWS?

Before you begin make sure to initialize your AWS credential on your local machine. Follow the guide at https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html.

5.1 Install the following Tools

Chocolatey (Windows), Homebrew (Mac)
Quarkus CLI - https://quarkus.io/guides/cli-tooling
AWS SAM CLI - https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html
Make sure to follow the guide that matches your computer and install all the prerequisites if there are given.

6. Quarkus CLI

You can now use Quarkus CLI to run your project:

>quarkus dev

Image description

Or create a build:

>quarkus build

Image description

This command should build various files in the target folder such as sam.jvm.saml and function.zip which we will use later in the deployment.

If you're looking for another way to build natively check https://www.czetsuyatech.com/2022/07/quarkus-compile-natively-using-graalvm-docker-as-builder.html.

  1. Deploy your Quarkus Lambda Function Make sure that you have already built your project and set up the AWS credential.

Let's do the deployment.

>sam deploy -g -t target/sam.jvm.yaml

Image description

Installation Summary.

Image description

The sam.jvm.yml file contains the AWS CloudFormation resources that will be created on AWS by this command. First, it will list these resources for you to verify, and once you are satisfied hit enter.

8. Removing the Quarkus Lambda

Don't remove the function from the Lambda screen, instead go to CloudFormation to remove all the associated resources.

9. More Quarkus AWS Libraries

Aside from AWS Lambda, more AWS libraries are available in the Quarkus framework such as XRay, Alexa, HTTP, etc.

Top comments (0)