|
1 | 1 | ---
|
2 | 2 | title: Quarkus
|
3 |
| -description: This is a dummy description |
| 3 | +description: Use the Quarkus framework with LocalStack |
4 | 4 | template: doc
|
5 | 5 | sidebar:
|
6 | 6 | order: 3
|
7 | 7 | ---
|
8 | 8 |
|
9 |
| -Nada |
| 9 | +## Introduction |
| 10 | + |
| 11 | +Quarkus is a Java framework optimized for cloud, serverless, and containerized environments. |
| 12 | +Quarkus leverages a Kubernetes Native Java stack tailored for GraalVM & OpenJDK HotSpot, which further builds on various Java libraries and standards. |
| 13 | + |
| 14 | +Localstack is supported by Quarkus as a Dev service for Amazon Services. |
| 15 | +Quarkus Amazon Services automatically starts a LocalStack container in development mode and when running tests, and the extension client is configured automatically. |
| 16 | + |
| 17 | +## Getting started |
| 18 | + |
| 19 | +In this guide, we will demonstrate how you can create a service client for creating and managing Lambdas on LocalStack. |
| 20 | +The Lambda extension is based on [AWS Java SDK 2.x](https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/welcome.html). |
| 21 | + |
| 22 | +### Prerequisites |
| 23 | + |
| 24 | +- [LocalStack](/aws/getting-started/installation/) installed and running |
| 25 | +- [JDK 17+](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html) with `JAVA_HOME` configured properly |
| 26 | +- [Maven 3.8.1+](https://maven.apache.org/download.cgi) |
| 27 | +- [Docker](https://docs.docker.com/get-docker/) |
| 28 | + |
| 29 | +### Create a Maven project |
| 30 | + |
| 31 | +Create a new project with the following command: |
| 32 | + |
| 33 | +```bash |
| 34 | +mvn io.quarkus.platform:quarkus-maven-plugin:3.6.3:create \ |
| 35 | + -DprojectGroupId=org.acme \ |
| 36 | + -DprojectArtifactId=amazon-lambda-quickstart \ |
| 37 | + -DclassName="org.acme.lambda.QuarkusLambdaSyncResource" \ |
| 38 | + -Dpath="/sync" \ |
| 39 | + -Dextensions="resteasy-reactive-jackson,amazon-lambda" |
| 40 | +cd amazon-lambda-quickstart |
| 41 | +``` |
| 42 | + |
| 43 | +The above command generates a Maven project structure with imports for RESTEasy Reactive/JAX-RS and Amazon Lambda Client extensions. |
| 44 | + |
| 45 | +### Configure Lambda Client |
| 46 | + |
| 47 | +Both Lambda clients (sync and async) can be configured through the `application.properties` file, which should be located in the `src/main/resources` directory. |
| 48 | +Additionally, ensure that a suitable implementation of the sync client is added to the `classpath`. |
| 49 | +By default, the extension employs the URL connection HTTP client, so it's necessary to include a URL connection client dependency in the `pom.xml` file: |
| 50 | + |
| 51 | +```xml |
| 52 | +<dependency> |
| 53 | + <groupId>software.amazon.awssdk</groupId> |
| 54 | + <artifactId>url-connection-client</artifactId> |
| 55 | +</dependency> |
| 56 | +``` |
| 57 | + |
| 58 | +If you want to use Apache HTTP client instead, configure it as follows in `application.properties`: |
| 59 | + |
| 60 | +```xml |
| 61 | +quarkus.lambda.sync-client.type=apache |
| 62 | +``` |
| 63 | + |
| 64 | +Add the following dependencies to the `pom.xml` file: |
| 65 | + |
| 66 | +```xml |
| 67 | +<dependency> |
| 68 | + <groupId>software.amazon.awssdk</groupId> |
| 69 | + <artifactId>apache-client</artifactId> |
| 70 | +</dependency> |
| 71 | +```` |
| 72 | + |
| 73 | +To configure LocalStack, add the following properties to the `application.properties` file: |
| 74 | + |
| 75 | +```bash |
| 76 | +quarkus.lambda.endpoint-override=http://localhost:4566 |
| 77 | + |
| 78 | +quarkus.lambda.aws.region=us-east-1 |
| 79 | +quarkus.lambda.aws.credentials.type=static |
| 80 | +quarkus.lambda.aws.credentials.static-provider.access-key-id=test-key |
| 81 | +quarkus.lambda.aws.credentials.static-provider.secret-access-key=test-secret |
| 82 | +``` |
| 83 | + |
| 84 | +### Package the application |
| 85 | + |
| 86 | +You can package the application with the following command: |
| 87 | + |
| 88 | +```bash |
| 89 | +$ ./mvnw clean package |
| 90 | +``` |
| 91 | + |
| 92 | +You can further run the application in dev mode with the following command: |
| 93 | + |
| 94 | +```bash |
| 95 | +$ java -Dparameters.path=/quarkus/is/awesome/ -jar target/quarkus-app/quarkus-run.jar |
| 96 | +``` |
| 97 | + |
| 98 | +:::tip |
| 99 | +With GraalVM installed, you can also create a native executable binary using the following command: |
| 100 | + |
| 101 | +```bash |
| 102 | +$ ./mvnw clean package -Dnative. |
| 103 | +``` |
| 104 | +::: |
| 105 | + |
| 106 | +:::note |
| 107 | +Dev Services for Amazon Services is automatically enabled for each extension added to the `pom.xml`, except in the following scenarios: |
| 108 | + |
| 109 | +- When `quarkus.devservices.enabled` is set to false. |
| 110 | +- When `devservices.enabled` is set to false per extension (e.g., `quarkus.s3.devservices.enabled=false`). |
| 111 | +- When the `endpoint-override` is configured (e.g., `quarkus.s3.endpoint-override=http://localhost:4566`). |
| 112 | +::: |
| 113 | + |
| 114 | +## Supported extensions |
| 115 | + |
| 116 | +- [Lambda](https://docs.quarkiverse.io/quarkus-amazon-services/dev/amazon-lambda.html) |
| 117 | +- [S3](https://docs.quarkiverse.io/quarkus-amazon-services/dev/amazon-s3.html) |
| 118 | +- [SSM](https://docs.quarkiverse.io/quarkus-amazon-services/dev/amazon-ssm.html) |
| 119 | +- [SQS](https://docs.quarkiverse.io/quarkus-amazon-services/dev/amazon-sqs.html) |
| 120 | +- [SNS](https://docs.quarkiverse.io/quarkus-amazon-services/dev/amazon-sns.html) |
| 121 | +- [SES](https://docs.quarkiverse.io/quarkus-amazon-services/dev/amazon-ses.html) |
| 122 | +- [Secrets Manager](https://docs.quarkiverse.io/quarkus-amazon-services/dev/amazon-secretsmanager.html) |
| 123 | +- [KMS](https://docs.quarkiverse.io/quarkus-amazon-services/dev/amazon-kms.html) |
| 124 | +- [IAM](https://docs.quarkiverse.io/quarkus-amazon-services/dev/amazon-iam.html) |
| 125 | + |
| 126 | +## Configuration |
| 127 | + |
| 128 | +The following configuration properties are fixed at build time. |
| 129 | +All the other configuration properties can be overridden at runtime. |
| 130 | + |
| 131 | +| Property | Type | Default | |
| 132 | +|----------------------------------------------------------|------------------------|--------------------------------------| |
| 133 | +| `quarkus.aws.devservices.localstack.image-name` | string | `localstack/localstack:3.0.1` | |
| 134 | +| `quarkus.aws.devservices.localstack.init-scripts-folder` | string | | |
| 135 | +| `quarkus.aws.devservices.localstack.init-scripts-classpath`| string | | |
| 136 | +| `quarkus.aws.devservices.localstack.init-completion-msg` | string | | |
| 137 | +| `quarkus.aws.devservices.localstack.container-properties` | `Map<String,String>` | | |
| 138 | +| `quarkus.aws.devservices.localstack.additional-services."additional-services".enabled` | boolean | | |
| 139 | +| `quarkus.aws.devservices.localstack.additional-services."additional-services".shared` | boolean | `false` | |
| 140 | +| `quarkus.aws.devservices.localstack.additional-services."additional-services".service-name` | string | `localstack` | |
| 141 | +| `quarkus.aws.devservices.localstack.additional-services."additional-services".container-properties` | `Map<String,String>` | | |
| 142 | + |
| 143 | +:::note |
| 144 | +- If `quarkus.aws.devservices.localstack.additional-services."additional-services".enabled` is set to `true` and the endpoint-override is not configured, LocalStack will be started and utilized instead of the provided configuration. |
| 145 | + For all services excluding Cognito, LocalStack will function as the core cloud emulator. |
| 146 | + In the case of Cognito, the emulation/mocking will be done by Moto. |
| 147 | +- The `quarkus.aws.devservices.localstack.additional-services."additional-services".shared` indicates whether the LocalStack container managed by Dev Services is shared. |
| 148 | + In shared mode, Quarkus utilizes label-based service discovery, specifically the `quarkus-dev-service-localstack` label, to identify running containers. |
| 149 | + If a matching container is found, it is used. |
| 150 | + Otherwise, Dev Services initiates a new container. |
| 151 | + It's important to note that sharing is not supported for the Cognito extension. |
| 152 | +- In `quarkus.aws.devservices.localstack.additional-services."additional-services".service-name`, the value of the `quarkus-dev-service-localstack` label is attached to the initiated container. |
| 153 | + In dev mode, when the shared flag is true, Dev Services checks for a container with the `quarkus-dev-service-localstack` label set to the configured value before starting a new one. |
| 154 | + If found, it utilizes the existing container. |
| 155 | + Otherwise, it creates a new container with the `quarkus-dev-service-localstack` label set to the specified value. |
| 156 | + In test mode, Dev Services groups services with the same service-name value into a single container instance. |
| 157 | + This property is useful when there's a requirement for multiple shared LocalStack instances. |
| 158 | +::: |
| 159 | + |
| 160 | +### Specific configuration |
| 161 | + |
| 162 | +Dev Services can support specific configurations passed to the LocalStack container. |
| 163 | +These configurations can be globally applied to all containers or specified individually per service. |
| 164 | + |
| 165 | +```bash |
| 166 | +quarkus.aws.devservices.localstack.image-name=localstack/localstack:3.0.3 |
| 167 | +quarkus.dynamodb.devservices.container-properties.DYNAMODB_HEAP_SIZE=1G |
| 168 | +``` |
| 169 | + |
| 170 | +### Additional services |
| 171 | + |
| 172 | +To start additional services for which a Quarkus extension does not exist or is not imported in the project, use the `additional-services` property: |
| 173 | + |
| 174 | +```bash |
| 175 | +quarkus.aws.devservices.localstack.additional-services."kinesis".enabled=true |
| 176 | +quarkus.aws.devservices.localstack.additional-services."redshift".enabled=true |
| 177 | +``` |
0 commit comments