Add a Quarkus Funqy extension for Amazon Lambda deployment(quarkus-funqy-amazon-lambda) and remove the quarkus-amazon-lambda-http extension:
quarkus ext add quarkus-funqy-amazon-lambda
quarkus ext remove quarkus-amazon-lambda-http
Update the GreetingResource.java
file to use @funq
annotation. Then, remove unnecessary packages and annotations(@Path, @PathParam, @GET).
package org.acme;
import jakarta.inject.Inject;
import io.quarkus.funqy.Funq;
public class GreetingResource {
@Inject
GreetingService greetingService;
@Funq
public String greeting(String name) {
return greetingService.greeting(name);
}
@Funq
public String hello() {
return "Hello Serverless";
}
}
Before you’ll deploy the function to AWS Lambda, you need to specify a function name. Add the following key and value in application.properties
file:
quarkus.funqy.export=greeting
Then, package the application once again using the following command:
quarkus build --no-tests
Or run the following maven package command:
./mvnw clean package -DskipTests
Now, you have a new bash script to make you easier to deploy the function to AWS Lambda without using HTTP Gateway API, S3, ARN:
-
manage.sh
- wrapper around aws lambda cli calls
Open and inspect manage.sh
file in the target directory.
You don’t need to use the SAM CLI directly since manage.sh script is a wrapper to create and delete a function simply.
Let’s update the RUNTIME in the target/manage.sh
file to use Java 17 again.
RUNTIME=java17
Save the file.
Run the script file with LAMBDA_ROLE_ARN resource. If you have no IAM roles, you need to create a new one in the AWS console. Find more information here.
LAMBDA_ROLE_ARN=<YOUR_OWN_ARN> sh target/manage.sh create
The output should look like:
{
"FunctionName": "EnterServerlessFunction",
"FunctionArn": "arn:aws:lambda:us-east-1:716861016243:function:EnterServerlessFunction",
"Runtime": "java17",
"Role": "arn:aws:iam::716861016243:role/lambda-role",
"Handler": "io.quarkus.funqy.lambda.FunqyStreamHandler::handleRequest",
"CodeSize": 15614407,
"Description": "",
"Timeout": 15,
"MemorySize": 256,
"LastModified": "2023-05-03T02:59:36.252+0000",
"CodeSha256": "4F2ZIQVC5x4c5AMius5hM+815ZSLB1AyzfideNpNxLk=",
"Version": "$LATEST",
"TracingConfig": {
"Mode": "PassThrough"
},
"RevisionId": "19f56627-6307-467f-a621-f01cd8d4a4b8",
"State": "Pending",
"StateReason": "The function is being created.",
"StateReasonCode": "Creating",
"PackageType": "Zip",
"Architectures": [
"x86_64"
],
"EphemeralStorage": {
"Size": 512
},
"SnapStart": {
"ApplyOn": "None",
"OptimizationStatus": "Off"
}
}
Note
|
You probably see "State": "Pending" in the result then go back to AWS web console to check if a new function is created or not. |
Press q
to exit from the output terminal.
Go back to Amazon web console then validate a new function(EnterServerlessFunctions
):
Click the function name(EnterServerlessFunctions
) then select Test
menu. Input "Funqy"
in the text area and greeting
in Name field:
Click on Test
button. Then, you will see the result as below. Click on Details
to collapse the test details.
If the function is not required to run on AWS Lambda, remove it using the following command:
LAMBDA_ROLE_ARN=<YOUR_OWN_ARN> sh target/manage.sh delete
You can also remove the other HTTP gateway API functions using the following command:
sam delete --stack-name quarkus-native-function
If you want to deploy the Quarkus Funqy application as a native executables, you need to package a native executable first using ./mvnw clean package -Pnative
then run the wrapper script using LAMBDA_ROLE_ARN=<YOUR_OWN_ARN> sh target/manage.sh native create
.