Quarkus is a Java framework optimized for cloud, serverless, and containerized environments. Quarkus leverages a Kubernetes Native Java stack tailored for GraalVM & OpenJDK HotSpot, which further builds on various Java libraries and standards.
Localstack is supported by Quarkus as a Dev service for Amazon Services. Quarkus Amazon Services automatically starts a LocalStack container in development mode and when running tests, and the extension client is configured automatically.
In this guide, we will demonstrate how you can create a service client for creating and managing Lambdas on LocalStack. The Lambda extension is based on AWS Java SDK 2.x.
Create a Maven project
Create a new project with the following command:
$ mvn io.quarkus.platform:quarkus-maven-plugin:3.6.3:create \
$ cd amazon-lambda-quickstart
The above command generates a Maven project structure with imports for RESTEasy Reactive/JAX-RS and Amazon Lambda Client extensions.
Configure Lambda Client
Both Lambda clients (sync and async) can be configured through the
application.properties file, which should be located in the
src/main/resources directory. Additionally, ensure that a suitable implementation of the sync client is added to the
classpath. By default, the extension employs the URL connection HTTP client, so it’s necessary to include a URL connection client dependency in the
If you want to use Apache HTTP client instead, configure it as follows in
Add the following dependencies to the
To configure LocalStack, add the following properties to the
Package the application
You can package the application with the following command:
$ ./mvnw clean package
You can further run the application in dev mode with the following command:
$ java -Dparameters.path=/quarkus/is/awesome/ -jar target/quarkus-app/quarkus-run.jar
With GraalVM installed, you can also create a native executable binary using the following command:
$ ./mvnw clean package -Dnative.
Dev Services for Amazon Services is automatically enabled for each extension added to the
pom.xml, except in the following scenarios:
quarkus.devservices.enabledis set to false.
devservices.enabledis set to false per extension (e.g.,
- When the
endpoint-overrideis configured (e.g.,
The following configuration properties are fixed at build time. All the other configuration properties can be overridden at runtime.
quarkus.aws.devservices.localstack.additional-services."additional-services".enabledis set to
trueand the endpoint-override is not configured, LocalStack will be started and utilized instead of the provided configuration. For all services excluding Cognito, LocalStack will function as the core cloud emulator. In the case of Cognito, the emulation/mocking will be done by Moto.
quarkus.aws.devservices.localstack.additional-services."additional-services".sharedindicates whether the LocalStack container managed by Dev Services is shared. In shared mode, Quarkus utilizes label-based service discovery, specifically the
quarkus-dev-service-localstacklabel, to identify running containers. If a matching container is found, it is used. Otherwise, Dev Services initiates a new container. It’s important to note that sharing is not supported for the Cognito extension.
quarkus.aws.devservices.localstack.additional-services."additional-services".service-name, the value of the
quarkus-dev-service-localstacklabel is attached to the initiated container. In dev mode, when the shared flag is true, Dev Services checks for a container with the
quarkus-dev-service-localstacklabel set to the configured value before starting a new one. If found, it utilizes the existing container. Otherwise, it creates a new container with the
quarkus-dev-service-localstacklabel set to the specified value. In test mode, Dev Services groups services with the same service-name value into a single container instance. This property is useful when there’s a requirement for multiple shared LocalStack instances.
Dev Services can support specific configurations passed to the LocalStack container. These configurations can be globally applied to all containers or specified individually per service.
To start additional services for which a Quarkus extension does not exist or is not imported in the project, use the