Quarkus JAX-RS App Deployed as AWS Lambda with AWS CDK

Overview

MicroProfile with Quarkus as AWS Lambda Function deployed with Cloud Development Kit (CDK) v2 for Java

A lean starting point for building, testing and deploying Quarkus MicroProfile applications deployed as AWS Lambda behind API Gateway. The business logic, as well as, the Infrastructure as Code deployment are implemented with Java.

TL;DR

A Quarkus MicroProfile application:

@Path("hello")
@ApplicationScoped
public class GreetingResource {

    @Inject
    Greeter greeter;

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String hello() {
        return this.greeter.greetings();
    }

    @POST
    @Consumes(MediaType.TEXT_PLAIN)
    public void hello(String message) {
        this.greeter.greetings(message);
    }
}

...with an additional dependency / extension for AWS REST APIs Gateway:

<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-amazon-lambda-rest</artifactId>
</dependency>

or HTTP APIs Gateway (default configuration):

<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-amazon-lambda-http</artifactId>
</dependency>

...deployed with AWS Cloud Development Kit:

Function createFunction(String functionName,String functionHandler, 
    Map<String,String> configuration, int memory, int maximumConcurrentExecution, int timeout) {

        return Function.Builder.create(this, functionName)
                .runtime(Runtime.JAVA_11)
                .code(Code.fromAsset("../lambda/target/function.zip"))
                .handler(functionHandler)
                .memorySize(memory)
                .functionName(functionName)
                .environment(configuration)
                .timeout(Duration.seconds(timeout))
                .reservedConcurrentExecutions(maximumConcurrentExecution)
                .build();
    }

You choose between HTTP APIs gateway and REST APIs gateway with the httpAPIGatewayIntegration variable:

public class CDKApp {
    public static void main(final String[] args) {

            var app = new App();
            var appName = "quarkus-apigateway-lambda-cdk";
            Tags.of(app).add("project", "MicroProfile with Quarkus on AWS Lambda");
            Tags.of(app).add("environment","development");
            Tags.of(app).add("application", appName);

            var httpAPIGatewayIntegration = true;
            new CDKStack(app, appName, true);
            app.synth();
        }
    }
}

Prerequisites

Java

  1. Java / openJDK is installed
  2. Maven is installed

AWS

Same installation as aws-cdk-plain:

  1. For max convenience use the default profile. A profile named default doesn't have to be specificed with the --profile flag or configured in CDK applications.
  2. Install AWS CDK CLI
  3. cdk boostrap --profile YOUR_AWS_PROFILE

This template ships with AWS HTTP APIs Gateway. REST APIs Gateway is also supported. You can switch between both by using the corresponding extension (see Choosing between HTTP APIs and REST APIs.

Private APIs are only supported by REST API Gateway.

See you at: airhacks.live

in action

full build

Build the Quarkus project lambda and deploy it with cdk as AWS Lambda:

cd lambda
./buildAndDeployDontAsk.sh

continuous and accelerated deployment

To continuously deploy the AWS Lambda at any changes, perform:

cd cdk
cdk watch

Now on every: mvn package in lambda directory / project the JAX-RS application is re-deployed automatically.

local deployment

You can run the lambda project as regular Quarkus application with:

mvn compile quarkus:dev

The application is available under: http://localhost:8080/hello

Deploying MicroProfile / Quarkus Application as AWS Lambda with Java AWS CDK

Deploying MicroProfile / Quarkus Application as AWS Lambda with Java AWS CDK

Accelarating deployments with CDK v2 Watch

Using cdk watch for faster deployments

Accelerating Deployment with CDK v2 Watch

See you at: airhacks.live

You might also like...

Spring Boot microservices app with Spring Cloud, Robust and resilient backend managing e-Commerce app

Spring Boot microservices app with Spring Cloud, Robust and resilient backend managing e-Commerce app

e-Commerce-boot μServices Important Note: This project's new milestone is to move The whole system to work on Kubernetes, so stay tuned. Introduction

Dec 23, 2022

This app corrects your sitting posture and provides feedback in real time in conjunction with the app. A sensor of 31 cells detects your posture to get better life-wellness

This app corrects your sitting posture and provides feedback in real time in conjunction with the app. A sensor of 31 cells detects your posture to get better life-wellness

Notichair 실시간 자세분석 및 교정 스마트체어 🏆 상명대학교 PRIME 경진대회 수상 🏆 요구사항 31-cell sensor (mdxs-16-5610) 목차 1. 소개 프로젝트 내용 소개 2. 개발 환경 사전 설정 및 환경 구축 3. 기능 Sensors Ap

Jan 15, 2022

An implementation of a sample E-Commerce app in k8s. This online retail marketplace app uses Spring Boot, React, and YugabyteDB.

An implementation of a sample E-Commerce app in k8s. This online retail marketplace app uses Spring Boot, React, and YugabyteDB.

An implementation of a sample E-Commerce app in k8s. This online retail marketplace app uses Spring Boot, React, and YugabyteDB.

Oct 27, 2022

All I know about Spring as a Spring Boot app

All about Spring This repository contains all the knowledge I have and all the things I can do with Spring You can download v1.0.0 java-doc here In th

Jul 16, 2022

Spring Boot Jhipster Photo Gallery App

Spring Boot Jhipster Photo Gallery App

Spring Boot Jhipster Photo Gallery Example Prerequisites Docker 19.03+ Docker Compose 1.25+ Build Docker Image ./mvnw -Pprod jib:dockerBuild clean ver

Aug 20, 2021

An TikTok-like app

An TikTok-like app

Video-app An TikTok likes app Middleware and db all tools below installed by docker please make sure you have installed docker in your machine tool ve

Dec 26, 2021

Prevent Screenshots in your React Native app when needed. 🦄

React Native Prevent Screenshots Prevent Screenshots in your React Native app when needed. 🦄 Installation First, you need to install the package usin

Oct 19, 2022

Components to control your app status and navigation bars.

Components to control your app status and navigation bars.

➖ react-native-bars Components to control your app status and navigation bars. Heavily inspired by the built-in StatusBar module and react-native-tran

Jan 3, 2023
Comments
  • Added tiered compilation

    Added tiered compilation

    Hi Adam,

    adding tiered compilation to the function reduces your cold starts by around 1 second. You can find a benchmark between tiered and non-tiered compilation below. Test was done doing 10 concurrent requests per second for 60 seconds.

    With tiered compilation (0 means warm start, 1 means cold start): tiered

    Without tiered compilation:

    no_tiered

    More infos also here.

    Best, Max

    opened by maschnetwork 1
  • Add maven wrapper

    Add maven wrapper

    To build the artifacts in lambda and lambda-st the readme talks about using the included maven wrapper to build and run the service. However there is no wrapper included in the repository.

    This pull request adds a maven wrapper to lambda and lambda-st.

    opened by roamingthings 0
Releases(v1.0)
  • v1.0(Apr 18, 2022)

    • Quarkus / MicroProfile application is deployed as function
    • Both: Http API and REST API Gateway are supported: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-vs-rest.html
    Source code(tar.gz)
    Source code(zip)
Owner
Adam Bien
I'm working with Java technology since JDK 1.0 and with JavaScript since LiveScript. A few times a year, I deliver live, virtual workshops: airhacks.live
Adam Bien
This repository shows how to natively extend Quarkus with a custom ConfigSource to use AWS AppConfig values when injecting config properties with @ConfigProperty.

Using AWS AppConfig in a custom MicroProfile ConfigSource This repository shows how to natively extend Quarkus with a custom ConfigSource to use AWS A

AWS Samples 8 May 19, 2022
This is a blank project for Java development with CDK.

Welcome to your CDK Java project! This is a blank project for Java development with CDK. The cdk.json file tells the CDK Toolkit how to execute your a

Kaio Fábio Prates Prudêncio 1 Feb 4, 2022
A simple quarkus app with hibernate as ORM, used to show the features of Hibernate Search

beer-manager-hibernate-search Project This project uses Quarkus, the Supersonic Subatomic Java Framework. If you want to learn more about Quarkus, ple

Sedona Solutions 3 Jan 6, 2022
backend for a sharing app using SpringBoot, Redis, MySQL, and AWS S3.

moments_v2_backend (Work In Progress) backend for a sharing app using SpringBoot, Redis, MySQL, and AWS S3. This is the second version of my project S

Haiming Sun 53 Dec 26, 2022
With react-native-update-in-app library you can easily implement in-app updates in your React Native app using CDN or any other file server

React Native In-App update With react-native-update-in-app library you can easily implement in-app updates in your React Native app using CDN or any o

Nepein Andrey 7 Dec 21, 2022
Quarkus: Supersonic Subatomic Java.

Quarkus - Supersonic Subatomic Java Quarkus is a Cloud Native, (Linux) Container First framework for writing Java applications. Container First: Minim

QuarkusIO 11.2k Jan 3, 2023
An estate management api based on the hexagonal architecture, built on top of Quarkus

An estate management api based on the hexagonal architecture, built on top of Quarkus

Mudi Lukman 2 Mar 30, 2022
Curso da Stack Quarkus - Alura

bitcoin Project This project uses Quarkus, the Supersonic Subatomic Java Framework. If you want to learn more about Quarkus, please visit its website:

null 2 Oct 29, 2021
Quarkus extension for launching an in-process Wiremock server

Quarkus extension for running Wiremock in DEVELOPMENT mode This extension is currently not published in any maven repository. If you want to test this

Quarkiverse Hub 5 Dec 30, 2022
AWS SaaS Boost

AWS SaaS Boost Overview AWS SaaS Boost provides organizations with ready-to-use core software elements for successfully running SaaS workloads in the

Amazon Web Services - Labs 839 Dec 27, 2022