Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adambien/aws-quarkus-lambda-cdk-plain
Quarkus JAX-RS App Deployed with AWS CDK as AWS Lambda behind HTTP API, REST API, Application Load Balancer and as Function URL
https://github.com/adambien/aws-quarkus-lambda-cdk-plain
alb api-gateway aws aws-lambda cdk cdkv2 cloud elb elbv2 faas functionurl furl java lambda loadbalancer microservice serverless
Last synced: 3 days ago
JSON representation
Quarkus JAX-RS App Deployed with AWS CDK as AWS Lambda behind HTTP API, REST API, Application Load Balancer and as Function URL
- Host: GitHub
- URL: https://github.com/adambien/aws-quarkus-lambda-cdk-plain
- Owner: AdamBien
- License: mit
- Created: 2021-11-18T21:08:36.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-14T12:09:31.000Z (3 months ago)
- Last Synced: 2025-01-30T13:09:18.270Z (11 days ago)
- Topics: alb, api-gateway, aws, aws-lambda, cdk, cdkv2, cloud, elb, elbv2, faas, functionurl, furl, java, lambda, loadbalancer, microservice, serverless
- Language: Java
- Homepage:
- Size: 129 KB
- Stars: 62
- Watchers: 7
- Forks: 28
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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:
```java
@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](https://quarkus.io/guides/amazon-lambda-http) for AWS REST APIs Gateway:```xml
io.quarkus
quarkus-amazon-lambda-rest```
or HTTP APIs Gateway (default configuration):
```xml
io.quarkus
quarkus-amazon-lambda-http```
...deployed with AWS Cloud Development Kit:
```java
Function createFunction(String functionName,String functionHandler,
Map configuration, int memory, int maximumConcurrentExecution, int timeout) {return Function.Builder.create(this, functionName)
.runtime(Runtime.JAVA_21)
.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:``` java
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](https://maven.apache.org/) is installed## AWS
Same installation as [aws-cdk-plain](https://github.com/AdamBien/aws-cdk-plain):
0. For max convenience use the [`default` profile](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html). A profile named `default` doesn't have to be specificed with the `--profile` flag or configured in CDK applications.
1. Install [AWS CDK CLI](https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html)
2. [`cdk boostrap --profile YOUR_AWS_PROFILE`](https://docs.aws.amazon.com/cdk/latest/guide/bootstrapping.html)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](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-vs-rest.html).
Private APIs are only supported by [REST API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-private-apis.html).
You can also build AWS Lambda `function.zip` and executable Quarkus JAR by extracting the extension into a Maven profile. Checkout: [https://adambien.blog/roller/abien/entry/hybrid_microprofile_deployments_with_quarkus](https://adambien.blog/roller/abien/entry/hybrid_microprofile_deployments_with_quarkus).
See you at: [airhacks.live](https://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](https://i.ytimg.com/vi/NA0WjIgp4CQ/mqdefault.jpg)](https://www.youtube.com/embed/NA0WjIgp4CQ?rel=0)
## Accelarating deployments with CDK v2 Watch
Using `cdk watch` for faster deployments
[![Accelerating Deployment with CDK v2 Watch](https://i.ytimg.com/vi/SK7ic9wTYqU/mqdefault.jpg)](https://www.youtube.com/embed/SK7ic9wTYqU?rel=0)
See you at: [airhacks.live](https://airhacks.live)