Reputation: 454
The documentation shows that the exposed handler (via io.quarkus.amazon.lambda.runtime.QuarkusStreamHandler::handleRequest
in the packaged application) is configured by setting quarkus.lambda.handler
in application.properties
. However in my case I'd like to deploy multiple handlers from the same project.
Does anyone know of a way, or whether it's possible, to expose more than a single handler from a quarkus-lambda project?
Edit: After reading through https://github.com/quarkusio/quarkus/blob/master/extensions/amazon-lambda/runtime/src/main/java/io/quarkus/amazon/lambda/runtime/AmazonLambdaRecorder.java#L89 it seems that this is indeed not possible right now, is that correct?
Upvotes: 5
Views: 3071
Reputation: 1804
This is now possible by setting the QUARKUS_LAMBDA_HANDLER
environment variable for each lambda function. This environment variable will override quarkus.lambda.handler
in application.properties
.
For instance, if you have multiple handlers defined as so:
@Named("Test")
public class TestLambda implements RequestHandler<InputObject, OutputObject> {
@Inject
ProcessingService service;
@Override
public OutputObject handleRequest(InputObject input, Context context) {
return new OutputObject().setRequestId("1").setResult("Test");
}
}
@Named("Sample")
public class SampleLambda implements RequestHandler<InputObject, OutputObject> {
@Inject
ProcessingService service;
@Override
public OutputObject handleRequest(InputObject input, Context context) {
return new OutputObject().setRequestId("2").setResult("Sample");
}
}
You could build the single project and deploy multiple functions with the following SAM template.
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: AWS Serverless Quarkus - quarkus-amazon-lambda-common-deployment
Globals:
Api:
EndpointConfiguration: REGIONAL
BinaryMediaTypes:
- "*/*"
Resources:
TestFunction:
Type: AWS::Serverless::Function
Properties:
Handler: io.quarkus.amazon.lambda.runtime.QuarkusStreamHandler::handleRequest
Runtime: java11
CodeUri: target/function.zip
MemorySize: 256
Timeout: 15
Policies: AWSLambdaBasicExecutionRole
Environment:
Variables:
QUARKUS_LAMBDA_HANDLER: Test
Events:
TestFunction:
Type: Api
Properties:
Path: /test
Method: get
SampleFunction:
Type: AWS::Serverless::Function
Properties:
Handler: io.quarkus.amazon.lambda.runtime.QuarkusStreamHandler::handleRequest
Runtime: java11
CodeUri: target/function.zip
MemorySize: 256
Timeout: 15
Policies: AWSLambdaBasicExecutionRole
Environment:
Variables:
QUARKUS_LAMBDA_HANDLER: Sample
Events:
HelloWorld:
Type: Api
Properties:
Path: /sample
Method: get
Upvotes: 6
Reputation: 1205
You should just write a RestEasy Resource and then follow the steps written here:
https://quarkus.io/guides/amazon-lambda-http
For a full example with RestEasy & DynamoDB, read these:
Basically, the idea is that you just write Rest Resources in Quarkus and Quarkus deploys & configures all your Resource endpoints as Api-Gateways and Lambda's & Handlers in AWS via the SAM CLI.
Make sure you have these 2 dependencies in your classpath:
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>url-connection-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-amazon-lambda-http</artifactId>
</dependency>
Then run:
mvn clean install
To make sure that the necessary artifacts are created in your /target folder.
Upvotes: 1