You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## How can I use Powertools for AWS Lambda (Java) with Lombok?
8
8
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.
10
10
11
11
To enable in-place weaving feature you need to use following `aspectj-maven-plugin` configuration:
12
12
@@ -29,7 +29,7 @@ To enable in-place weaving feature you need to use following `aspectj-maven-plug
29
29
30
30
## How can I use Powertools for AWS Lambda (Java) with Kotlin projects?
31
31
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`.
33
33
No explicit configuration should be required for gradle projects.
34
34
35
35
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
47
47
</configuration>
48
48
```
49
49
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:
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`.
0 commit comments