Skip to content

Commit 4036d07

Browse files
committed
chore(v2): document use of aws-crt-client (aws-powertools#1092)
1 parent 8f176cc commit 4036d07

File tree

4 files changed

+147
-57
lines changed

4 files changed

+147
-57
lines changed

docs/FAQs.md

+90-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: Frequently Asked Questions
66

77
## How can I use Powertools for AWS Lambda (Java) with Lombok?
88

9-
Poweretools uses `aspectj-maven-plugin` to compile-time weave (CTW) aspects into the project. In case you want to use `Lombok` or other compile-time preprocessor for your project, it is required to change `aspectj-maven-plugin` configuration to enable in-place weaving feature. Otherwise the plugin will ignore changes introduced by `Lombok` and will use `.java` files as a source.
9+
Powertools uses `aspectj-maven-plugin` to compile-time weave (CTW) aspects into the project. In case you want to use `Lombok` or other compile-time preprocessor for your project, it is required to change `aspectj-maven-plugin` configuration to enable in-place weaving feature. Otherwise the plugin will ignore changes introduced by `Lombok` and will use `.java` files as a source.
1010

1111
To enable in-place weaving feature you need to use following `aspectj-maven-plugin` configuration:
1212

@@ -29,7 +29,7 @@ To enable in-place weaving feature you need to use following `aspectj-maven-plug
2929

3030
## How can I use Powertools for AWS Lambda (Java) with Kotlin projects?
3131

32-
Poweretools uses `aspectj-maven-plugin` to compile-time weave (CTW) aspects into the project. When using it with Kotlin projects, it is required to `forceAjcCompile`.
32+
Powertools uses `aspectj-maven-plugin` to compile-time weave (CTW) aspects into the project. When using it with Kotlin projects, it is required to `forceAjcCompile`.
3333
No explicit configuration should be required for gradle projects.
3434

3535
To enable `forceAjcCompile` you need to use following `aspectj-maven-plugin` configuration:
@@ -47,3 +47,91 @@ To enable `forceAjcCompile` you need to use following `aspectj-maven-plugin` con
4747
</configuration>
4848
```
4949

50+
## How can I use Powertools for AWS Lambda (Java) with the AWS CRT HTTP Client?
51+
52+
Powertools uses the `url-connection-client` as the default http client. The `url-connection-client` is a lightweight http client, which keeps the impact on Lambda cold starts to a minimum.
53+
With the [announcement](https://aws.amazon.com/blogs/developer/announcing-availability-of-the-aws-crt-http-client-in-the-aws-sdk-for-java-2-x/) of the `aws-crt-client` a new http client has been released, which offers faster SDK startup time and smaller memory footprint.
54+
55+
Unfortunately, replacing the `url-connection-client` dependency with the `aws-crt-client` will not immediately improve the lambda cold start performance and memory footprint,
56+
as the default version of the dependency contains low level libraries for all target runtimes (linux, macos, windows, etc).
57+
58+
Using the `aws-crt-client` in your project requires the exclusion of the `url-connection-client` transitive dependency from the powertools dependency.
59+
60+
```xml
61+
<dependency>
62+
<groupId>software.amazon.lambda</groupId>
63+
<artifactId>powertools-parameters</artifactId>
64+
<version>1.18.0</version>
65+
<exclusions>
66+
<exclusion>
67+
<groupId>software.amazon.awssdk</groupId>
68+
<artifactId>url-connection-client</artifactId>
69+
</exclusion>
70+
</exclusions>
71+
</dependency>
72+
```
73+
Next to adding the `aws-crt-client` and excluding the `aws-crt` dependency (contain all runtime libraries) it's required to set a specific runtime version of the `aws-crt` dependency by specifying the classifier for your specific target runtime.
74+
Specifying the specific target runtime makes sure all other target runtimes are excluded from the jar file, which will result in the benefit of improved cold start times.
75+
76+
```xml
77+
78+
<dependencies>
79+
<dependency>
80+
<groupId>software.amazon.awssdk</groupId>
81+
<artifactId>aws-crt-client</artifactId>
82+
<version>2.23.21</version>
83+
<exclusions>
84+
<exclusion>
85+
<groupId>software.amazon.awssdk.crt</groupId>
86+
<artifactId>aws-crt</artifactId>
87+
</exclusion>
88+
</exclusions>
89+
</dependency>
90+
91+
<dependency>
92+
<groupId>software.amazon.awssdk.crt</groupId>
93+
<artifactId>aws-crt</artifactId>
94+
<version>0.29.9</version>
95+
<classifier>linux-x86_64</classifier>
96+
</dependency>
97+
</dependencies>
98+
```
99+
100+
After configuring the dependencies it's required to specify the aws sdk http client.
101+
Most modules support a custom sdk client by leveraging the `.withClient()` method on the for instance the Provider singleton:
102+
103+
```java hl_lines="11-16 19-20 22"
104+
import static software.amazon.lambda.powertools.parameters.transform.Transformer.base64;
105+
106+
import com.amazonaws.services.lambda.runtime.Context;
107+
import com.amazonaws.services.lambda.runtime.RequestHandler;
108+
import software.amazon.awssdk.services.ssm.SsmClient;
109+
import software.amazon.lambda.powertools.parameters.ssm.SSMProvider;
110+
111+
public class RequestHandlerWithParams implements RequestHandler<String, String> {
112+
113+
// Get an instance of the SSMProvider. We can provide a custom client here if we want,
114+
// for instance to use the aws crt http client.
115+
SSMProvider ssmProvider = SSMProvider
116+
.builder()
117+
.withClient(
118+
SsmClient.builder()
119+
.httpClient(AwsCrtHttpClient.builder().build())
120+
.build()
121+
)
122+
.build();
123+
124+
public String handleRequest(String input, Context context) {
125+
// Retrieve a single param
126+
String value = ssmProvider
127+
.get("/my/secret");
128+
// We might instead want to retrieve multiple parameters at once, returning a Map of key/value pairs
129+
// .getMultiple("/my/secret/path");
130+
131+
// Return the result
132+
return value;
133+
}
134+
}
135+
```
136+
It has been considered to make the `aws-crt-client` the default http client in Lambda Powertools for Java, as mentioned in [Move SDK http client to CRT](https://github.com/aws-powertools/powertools-lambda-java/issues/1092),
137+
but due to the impact on the developer experience it was decided to stick with the `url-connection-client`.

docs/utilities/batch.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -530,19 +530,19 @@ Handlers can be provided when building the batch processor and are available for
530530
For instance for DynamoDB:
531531

532532
```java
533-
BatchMessageHandler<DynamodbEvent, StreamsEventResponse> handler = new BatchMessageHandlerBuilder()
534-
.withDynamoDbBatchHandler()
535-
.withSuccessHandler((m) -> {
536-
// Success handler receives the raw message
537-
LOGGER.info("Message with sequenceNumber {} was successfully processed",
538-
m.getDynamodb().getSequenceNumber());
539-
})
540-
.withFailureHandler((m, e) -> {
541-
// Failure handler receives the raw message and the exception thrown.
542-
LOGGER.info("Message with sequenceNumber {} failed to be processed: {}"
543-
, e.getDynamodb().getSequenceNumber(), e);
544-
})
545-
.buildWithMessageHander(this::processMessage);
533+
BatchMessageHandler<DynamodbEvent, StreamsEventResponse> handler = new BatchMessageHandlerBuilder()
534+
.withDynamoDbBatchHandler()
535+
.withSuccessHandler((m) -> {
536+
// Success handler receives the raw message
537+
LOGGER.info("Message with sequenceNumber {} was successfully processed",
538+
m.getDynamodb().getSequenceNumber());
539+
})
540+
.withFailureHandler((m, e) -> {
541+
// Failure handler receives the raw message and the exception thrown.
542+
LOGGER.info("Message with sequenceNumber {} failed to be processed: {}"
543+
, e.getDynamodb().getSequenceNumber(), e);
544+
})
545+
.buildWithMessageHander(this::processMessage);
546546
```
547547

548548
!!! info

docs/utilities/large_messages.md

+43-42
Original file line numberDiff line numberDiff line change
@@ -97,48 +97,49 @@ of amazon-sns-java-extended-client-lib.
9797
Depending on your version of Java (either Java 1.8 or 11+), the configuration slightly changes.
9898

9999
=== "Maven Java 11+"
100-
```xml hl_lines="3-7 16 18 24-27"
101-
<dependencies>
102-
...
103-
<dependency>
104-
<groupId>software.amazon.lambda</groupId>
105-
<artifactId>powertools-large-messages</artifactId>
106-
<version>{{ powertools.version }}</version>
107-
</dependency>
108-
...
109-
</dependencies>
110-
...
111-
<!-- configure the aspectj-maven-plugin to compile-time weave (CTW) the aws-lambda-powertools-java aspects into your project -->
112-
<build>
113-
<plugins>
114-
...
115-
<plugin>
116-
<groupId>dev.aspectj</groupId>
117-
<artifactId>aspectj-maven-plugin</artifactId>
118-
<version>1.13.1</version>
119-
<configuration>
120-
<source>11</source> <!-- or higher -->
121-
<target>11</target> <!-- or higher -->
122-
<complianceLevel>11</complianceLevel> <!-- or higher -->
123-
<aspectLibraries>
124-
<aspectLibrary>
125-
<groupId>software.amazon.lambda</groupId>
126-
<artifactId>powertools-large-messages</artifactId>
127-
</aspectLibrary>
128-
</aspectLibraries>
129-
</configuration>
130-
<executions>
131-
<execution>
132-
<goals>
133-
<goal>compile</goal>
134-
</goals>
135-
</execution>
136-
</executions>
137-
</plugin>
138-
...
139-
</plugins>
140-
</build>
141-
```
100+
101+
```xml hl_lines="3-7 16 18 24-27"
102+
<dependencies>
103+
...
104+
<dependency>
105+
<groupId>software.amazon.lambda</groupId>
106+
<artifactId>powertools-large-messages</artifactId>
107+
<version>{{ powertools.version }}</version>
108+
</dependency>
109+
...
110+
</dependencies>
111+
...
112+
<!-- configure the aspectj-maven-plugin to compile-time weave (CTW) the aws-lambda-powertools-java aspects into your project -->
113+
<build>
114+
<plugins>
115+
...
116+
<plugin>
117+
<groupId>dev.aspectj</groupId>
118+
<artifactId>aspectj-maven-plugin</artifactId>
119+
<version>1.13.1</version>
120+
<configuration>
121+
<source>11</source> <!-- or higher -->
122+
<target>11</target> <!-- or higher -->
123+
<complianceLevel>11</complianceLevel> <!-- or higher -->
124+
<aspectLibraries>
125+
<aspectLibrary>
126+
<groupId>software.amazon.lambda</groupId>
127+
<artifactId>powertools-large-messages</artifactId>
128+
</aspectLibrary>
129+
</aspectLibraries>
130+
</configuration>
131+
<executions>
132+
<execution>
133+
<goals>
134+
<goal>compile</goal>
135+
</goals>
136+
</execution>
137+
</executions>
138+
</plugin>
139+
...
140+
</plugins>
141+
</build>
142+
```
142143

143144
=== "Maven Java 1.8"
144145

docs/utilities/parameters.md

+1
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ To simplify the use of the library, you can chain all method calls before a get.
544544
.withTransformation(json) // json is a static import from Transformer.json
545545
.withDecryption() // enable decryption of the parameter value
546546
.get("/my/param", MyObj.class); // finally get the value
547+
```
547548

548549
### Create your own Provider
549550
You can create your own custom parameter store provider by implementing a handful of classes:

0 commit comments

Comments
 (0)