Skip to content

Commit d9895e8

Browse files
committed
Amazon service extensions
- Refactored DynamoDB extension - Added S3 client extension
1 parent 7318e86 commit d9895e8

File tree

109 files changed

+2643
-1063
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+2643
-1063
lines changed

azure-pipelines.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,11 @@ stages:
224224
parameters:
225225
timeoutInMinutes: 15
226226
modules:
227-
- amazon-dynamodb
227+
- amazon-services
228228
- amazon-lambda
229229
- amazon-lambda-http-it
230230
name: amazon
231-
dynamodb: true
231+
amazonStack: true
232232

233233
- template: ci-templates/native-build-steps.yaml
234234
parameters:

bom/deployment/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,21 @@
401401
<artifactId>quarkus-amazon-lambda-resteasy-deployment</artifactId>
402402
<version>${project.version}</version>
403403
</dependency>
404+
<dependency>
405+
<groupId>io.quarkus</groupId>
406+
<artifactId>quarkus-amazon-common-deployment</artifactId>
407+
<version>${project.version}</version>
408+
</dependency>
404409
<dependency>
405410
<groupId>io.quarkus</groupId>
406411
<artifactId>quarkus-amazon-dynamodb-deployment</artifactId>
407412
<version>${project.version}</version>
408413
</dependency>
414+
<dependency>
415+
<groupId>io.quarkus</groupId>
416+
<artifactId>quarkus-amazon-s3-deployment</artifactId>
417+
<version>${project.version}</version>
418+
</dependency>
409419
<dependency>
410420
<groupId>io.quarkus</groupId>
411421
<artifactId>quarkus-amazon-lambda-http-deployment</artifactId>

bom/runtime/pom.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,11 +626,23 @@
626626
<artifactId>quarkus-amazon-lambda-http</artifactId>
627627
<version>${project.version}</version>
628628
</dependency>
629+
630+
631+
<dependency>
632+
<groupId>io.quarkus</groupId>
633+
<artifactId>quarkus-amazon-common</artifactId>
634+
<version>${project.version}</version>
635+
</dependency>
629636
<dependency>
630637
<groupId>io.quarkus</groupId>
631638
<artifactId>quarkus-amazon-dynamodb</artifactId>
632639
<version>${project.version}</version>
633640
</dependency>
641+
<dependency>
642+
<groupId>io.quarkus</groupId>
643+
<artifactId>quarkus-amazon-s3</artifactId>
644+
<version>${project.version}</version>
645+
</dependency>
634646
<dependency>
635647
<groupId>io.quarkus</groupId>
636648
<artifactId>quarkus-azure-functions-http</artifactId>
@@ -2215,16 +2227,52 @@
22152227
<version>${aws-lambda-serverless-java-container.version}</version>
22162228
</dependency>
22172229

2230+
<dependency>
2231+
<groupId>software.amazon.awssdk</groupId>
2232+
<artifactId>sdk-core</artifactId>
2233+
<version>${awssdk.version}</version>
2234+
</dependency>
2235+
<dependency>
2236+
<groupId>software.amazon.awssdk</groupId>
2237+
<artifactId>aws-core</artifactId>
2238+
<version>${awssdk.version}</version>
2239+
</dependency>
2240+
<dependency>
2241+
<groupId>software.amazon.awssdk</groupId>
2242+
<artifactId>regions</artifactId>
2243+
<version>${awssdk.version}</version>
2244+
</dependency>
2245+
<dependency>
2246+
<groupId>software.amazon.awssdk</groupId>
2247+
<artifactId>auth</artifactId>
2248+
<version>${awssdk.version}</version>
2249+
</dependency>
2250+
<dependency>
2251+
<groupId>software.amazon.awssdk</groupId>
2252+
<artifactId>http-client-spi</artifactId>
2253+
<version>${awssdk.version}</version>
2254+
</dependency>
2255+
22182256
<dependency>
22192257
<groupId>software.amazon.awssdk</groupId>
22202258
<artifactId>dynamodb</artifactId>
22212259
<version>${awssdk.version}</version>
22222260
</dependency>
2261+
<dependency>
2262+
<groupId>software.amazon.awssdk</groupId>
2263+
<artifactId>s3</artifactId>
2264+
<version>${awssdk.version}</version>
2265+
</dependency>
22232266
<dependency>
22242267
<groupId>software.amazon.awssdk</groupId>
22252268
<artifactId>netty-nio-client</artifactId>
22262269
<version>${awssdk.version}</version>
22272270
</dependency>
2271+
<dependency>
2272+
<groupId>software.amazon.awssdk</groupId>
2273+
<artifactId>url-connection-client</artifactId>
2274+
<version>${awssdk.version}</version>
2275+
</dependency>
22282276
<dependency>
22292277
<groupId>software.amazon.awssdk</groupId>
22302278
<artifactId>apache-client</artifactId>

ci-templates/jvm-build-steps.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ steps:
1212
- script: docker run --rm --publish 5432:5432 --name build-postgres -e POSTGRES_USER=hibernate_orm_test -e POSTGRES_PASSWORD=hibernate_orm_test -e POSTGRES_DB=hibernate_orm_test -d postgres:10.5
1313
displayName: 'start postgres'
1414

15-
- script: docker run --rm --publish 8000:8000 --name build-dynamodb -d amazon/dynamodb-local:1.11.477
16-
displayName: 'start dynamodb'
15+
- script: docker run --rm --publish 8000:4569 --publish 8008:4572 --name build-amazon-service-clients -e SERVICES=s3,dynamodb -e START_WEB=0 -d localstack/localstack
16+
displayName: 'start aws local stack'
1717

1818
- bash: |
1919
sudo apt-get update &&
@@ -28,5 +28,5 @@ steps:
2828
goals: 'install'
2929
mavenOptions: $(MAVEN_OPTS)
3030
jdkVersionOption: ${{ parameters.jdk }}
31-
options: '-B --settings azure-mvn-settings.xml -Dnative-image.docker-build -Dtest-postgresql -Dtest-elasticsearch -Dtest-mysql -Dtest-dynamodb -Dtest-vault -Dno-format'
31+
options: '-B --settings azure-mvn-settings.xml -Dnative-image.docker-build -Dtest-postgresql -Dtest-elasticsearch -Dtest-mysql -Dtest-dynamodb -Dtest-s3 -Dtest-vault -Dno-format'
3232

ci-templates/native-build-steps.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ jobs:
2525
- ${{ if eq(parameters.postgres, 'true') }}:
2626
- script: docker run --rm --publish 5432:5432 --name build-postgres -e POSTGRES_USER=hibernate_orm_test -e POSTGRES_PASSWORD=hibernate_orm_test -e POSTGRES_DB=hibernate_orm_test -d postgres:10.5
2727
displayName: 'start postgres'
28-
- ${{ if eq(parameters.dynamodb, 'true') }}:
29-
- script: docker run --rm --publish 8000:8000 --name build-dynamodb -d amazon/dynamodb-local:1.11.477
30-
displayName: 'start dynamodb'
28+
- ${{ if eq(parameters.amazonStack, 'true') }}:
29+
- script: docker run --rm --publish 8000:4569 --publish 8008:4572 --name build-amazon-service-clients -e SERVICES=s3,dynamodb -e START_WEB=0 -d localstack/localstack
30+
displayName: 'start aws local stack'
3131
- ${{ if eq(parameters.keycloak, 'true') }}:
3232
- script: docker run --rm --publish 8180:8080 --name build-keycloak -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin -e JAVA_OPTS="-server -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djava.awt.headless=true -Dkeycloak.profile.feature.upload_scripts=enabled" -d quay.io/keycloak/keycloak
3333
displayName: 'start keycloak'

docs/src/main/asciidoc/dynamodb-guide.adoc renamed to docs/src/main/asciidoc/amazon-dynamodb-guide.adoc

Lines changed: 73 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Keep in mind it's actively developed and does not support yet all the features a
1919

2020
The Quarkus extension supports two programming models:
2121

22-
* Blocking access using the Apache HTTP Client
22+
* Blocking access using URL Connection HTTP client (by default) or the Apache HTTP Client
2323
* https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/basics-async.html[Asynchronous programming] based on JDK's `CompletableFuture` objects and the Netty HTTP client.
2424

2525
In this guide, we see how you can get your REST services to use the DynamoDB locally and on AWS.
@@ -99,15 +99,15 @@ First, we need a new project. Create a new project with the following command:
9999
[source,shell,subs=attributes+]
100100
----
101101
mvn io.quarkus:quarkus-maven-plugin:{quarkus-version}:create \
102-
-DprojectGroupId=org.acme \
102+
-DprojectGroupId=org.acme.amazon \
103103
-DprojectArtifactId=dynamodb-client \
104-
-DclassName="org.acme.dynamodb.FruitResource" \
104+
-DclassName="org.acme.amazon.dynamodb.FruitResource" \
105105
-Dpath="/fruits" \
106106
-Dextensions="resteasy-jsonb,dynamodb"
107107
----
108108

109109
This command generates a Maven structure importing the RESTEasy/JAX-RS and DynamoDB Client extensions.
110-
After this, the `amazon-dynamodb` extension has been added to your `pom.xml`.
110+
After this, the `dynamodb` extension has been added to your `pom.xml`.
111111

112112
== Creating JSON REST service
113113

@@ -117,7 +117,7 @@ First, let's create the `Fruit` bean as follows:
117117

118118
[source,java]
119119
----
120-
package org.acme.dynamodb;
120+
package org.acme.amazon.dynamodb;
121121
122122
import java.util.Map;
123123
import java.util.Objects;
@@ -180,11 +180,11 @@ public class Fruit {
180180
Nothing fancy. One important thing to note is that having a default constructor is required by the JSON serialization layer. The static `from` method creates a bean based on the `Map`
181181
object provided by the DynamoDB client response.
182182

183-
Now create a `org.acme.dynamodb.AbstractService` that will consist of helper methods that prepare DynamoDB request objects for reading and adding items to the table.
183+
Now create a `org.acme.amazon.dynamodb.AbstractService` that will consist of helper methods that prepare DynamoDB request objects for reading and adding items to the table.
184184

185185
[source,java]
186186
----
187-
package org.acme.dynamodb;
187+
package org.acme.amazon.dynamodb;
188188
189189
import java.util.HashMap;
190190
import java.util.Map;
@@ -232,11 +232,11 @@ public abstract class AbstractService {
232232
}
233233
----
234234

235-
Then, create a `org.acme.dynamodb.FruitSyncService` that will be the business layer of our application and stores/loads the fruits from DynamoDB using the synchronous client.
235+
Then, create a `org.acme.amazon.dynamodb.FruitSyncService` that will be the business layer of our application and stores/loads the fruits from DynamoDB using the synchronous client.
236236

237237
[source,java]
238238
----
239-
package org.acme.dynamodb;
239+
package org.acme.amazon.dynamodb;
240240
241241
import java.util.List;
242242
import java.util.stream.Collectors;
@@ -269,7 +269,7 @@ public class FruitSyncService extends AbstractService {
269269
}
270270
----
271271

272-
Now, edit the `org.acme.dynamodb.FruitResource` class as follows:
272+
Now, edit the `org.acme.amazon.dynamodb.FruitResource` class as follows:
273273

274274
[source,java]
275275
----
@@ -318,32 +318,64 @@ The implementation is pretty straightforward and you just need to define your en
318318
== Configuring DynamoDB clients
319319

320320
Both DynamoDB clients (sync and async) are configurable via the `application.properties` file that can be provided in the `src/main/resources` directory.
321+
Additionally, you need to add to the classpath a proper implementation of the sync client. By default the extension uses URL connection HTTP client, so
322+
add a URL connection client dependency to the `pom.xml` file:
323+
324+
[source,xml]
325+
----
326+
<dependency>
327+
<groupId>software.amazon.awssdk</groupId>
328+
<artifactId>url-connection-client</artifactId>
329+
</dependency>
330+
----
331+
332+
If you want to use Apache HTTP client instead, configure it as follows:
333+
[source,properties]
334+
----
335+
quarkus.amazon.sync-client.dynamodb.type=apache
336+
----
337+
338+
And add following dependency to the application `pom.xml`:
339+
[source,xml]
340+
----
341+
<dependency>
342+
<groupId>software.amazon.awssdk</groupId>
343+
<artifactId>apache-client</artifactId>
344+
<exclusions>
345+
<exclusion>
346+
<groupId>commons-logging</groupId>
347+
<artifactId>commons-logging</artifactId>
348+
</exclusion>
349+
</exclusions>
350+
</dependency>
351+
----
352+
NOTE: It's important to exclude `commons-logging` from the client dependency to force Apache HTTP client to use Quarkus logger.
321353

322354
If you're going to use a local DynamoDB instance, configure it as follows:
323355

324356
[source,properties]
325357
----
326-
quarkus.dynamodb.endpoint-override=http://localhost:8000
358+
quarkus.amazon.dynamodb.endpoint-override=http://localhost:8000
327359
328-
quarkus.dynamodb.aws.region=eu-central-1
329-
quarkus.dynamodb.aws.credentials.type=STATIC
330-
quarkus.dynamodb.aws.credentials.static-provider.access-key-id=test-key
331-
quarkus.dynamodb.aws.credentials.static-provider.secret-access-key=test-secret
360+
quarkus.amazon.aws.dynamodb.region=eu-central-1
361+
quarkus.amazon.aws.dynamodb.credentials.type=static
362+
quarkus.amazon.aws.dynamodb.credentials.static-provider.access-key-id=test-key
363+
quarkus.amazon.aws.dynamodb.credentials.static-provider.secret-access-key=test-secret
332364
----
333365

334-
- `quarkus.dynamodb.aws.region` - It's required by the client, but since you're using a local DynamoDB instance you can pick any valid AWS region.
335-
- `quarkus.dynamodb.aws.credentials.type` - Set `STATIC` credentials provider with any values for `access-key-id` and `secret-access-key`
336-
- `quarkus.dynamodb.endpoint-override` - Override the DynamoDB client to use a local instance instead of an AWS service
366+
- `quarkus.amazon.aws.dynamodb.region` - It's required by the client, but since you're using a local DynamoDB instance you can pick any valid AWS region.
367+
- `quarkus.amazon.aws.dynamodb.credentials.type` - Set `static` credentials provider with any values for `access-key-id` and `secret-access-key`
368+
- `quarkus.amazon.dynamodb.endpoint-override` - Override the DynamoDB client to use a local instance instead of an AWS service
337369

338370
If you want to work with an AWS account, you'd need to set it with:
339371
[source,properties]
340372
----
341-
quarkus.dynamodb.aws.region=<YOUR_REGION>
342-
quarkus.dynamodb.aws.credentials.type=DEFAULT
373+
quarkus.amazon.aws.dynamodb.region=<YOUR_REGION>
374+
quarkus.amazon.aws.dynamodb.credentials.type=default
343375
----
344376

345-
- `quarkus.dynamodb.aws.region` you should set it to the region where you provisioned the DynamoDB table,
346-
- `quarkus.dynamodb.aws.credentials.type` - use the `DEFAULT` credentials provider chain that looks for credentials in this order:
377+
- `quarkus.amazon.aws.dynamodb.region` you should set it to the region where you provisioned the DynamoDB table,
378+
- `quarkus.amazon.aws.dynamodb.credentials.type` - use the `default` credentials provider chain that looks for credentials in this order:
347379
- Java System Properties - `aws.accessKeyId` and `aws.secretKey`
348380
* Environment Variables - `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`
349381
* Credential profiles file at the default location (`~/.aws/credentials`) shared by all AWS SDKs and the AWS CLI
@@ -364,11 +396,11 @@ Depending on your system, that will take some time.
364396

365397
Thanks to the AWS SDK v2.x used by the Quarkus extension, you can use the asynchronous programming model out of the box.
366398

367-
Create a `org.acme.dynamodb.FruitAsyncService` that will be similar to our `FruitSyncService` but using an asynchronous programming model.
399+
Create a `org.acme.amazon.dynamodb.FruitAsyncService` that will be similar to our `FruitSyncService` but using an asynchronous programming model.
368400

369401
[source,java]
370402
----
371-
package org.acme.dynamodb;
403+
package org.acme.amazon.dynamodb;
372404
373405
import java.util.List;
374406
import java.util.concurrent.CompletableFuture;
@@ -400,11 +432,11 @@ public class FruitAsyncService extends AbstractService {
400432
}
401433
----
402434

403-
And an asynchronous REST resource:
435+
Create an asynchronous REST resource:
404436

405437
[source,java]
406438
----
407-
package org.acme.dynamodb;
439+
package org.acme.amazon.dynamodb;
408440
409441
import java.util.List;
410442
import java.util.concurrent.CompletionStage;
@@ -445,7 +477,22 @@ public class FruitAsyncResource {
445477
}
446478
----
447479

480+
And add Netty HTTP client dependency to the `pom.xml`:
481+
482+
[source,xml]
483+
----
484+
<dependency>
485+
<groupId>software.amazon.awssdk</groupId>
486+
<artifactId>netty-nio-client</artifactId>
487+
</dependency>
488+
----
489+
448490
== Configuration Reference
449491

492+
=== DynamoDB service configuration reference
493+
450494
include::{generated-dir}/config/quarkus-dynamodb.adoc[opts=optional, leveloffset=+1]
451495

496+
=== Amazon services common configuration reference
497+
498+
include::{generated-dir}/config/quarkus-amazon.adoc[opts=optional, leveloffset=+1]

extensions/amazon-dynamodb/deployment/src/main/java/io/quarkus/dynamodb/deployment/DynamodbClientBuildItem.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)