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,99 @@ 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 native system libraries for all supported runtimes and architectures (Linux, MacOS, Windows, AMD64, ARM64, etc). This makes the CRT client portable, without the user having to consider _where_ their code will run, but comes at the cost of JAR size.
57
+
58
+
### Configuring dependencies
59
+
60
+
Using the `aws-crt-client` in your project requires the exclusion of the `url-connection-client` transitive dependency from the powertools dependency.
61
+
62
+
```xml
63
+
<dependency>
64
+
<groupId>software.amazon.lambda</groupId>
65
+
<artifactId>powertools-parameters</artifactId>
66
+
<version>2.0.0</version>
67
+
<exclusions>
68
+
<exclusion>
69
+
<groupId>software.amazon.awssdk</groupId>
70
+
<artifactId>url-connection-client</artifactId>
71
+
</exclusion>
72
+
</exclusions>
73
+
</dependency>
74
+
```
75
+
Next, add the `aws-crt-client` and exclude the "generic" `aws-crt` dependency (contains all runtime libraries).
76
+
Instead, set a specific classifier of the `aws-crt` to use the one for your target runtime: either `linux-x86_64` for a Lambda configured for x86 or `linux-aarch_64` for Lambda using arm64.
77
+
78
+
!!! note "You will need to add a separate maven profile to build and debug locally when your development environment does not share the target architecture you are using in Lambda."
79
+
By specifying the specific target runtime, we prevent other target runtimes from being included in the jar file, resulting in a smaller Lambda package and improved cold start times.
80
+
81
+
```xml
82
+
83
+
<dependencies>
84
+
<dependency>
85
+
<groupId>software.amazon.awssdk</groupId>
86
+
<artifactId>aws-crt-client</artifactId>
87
+
<version>2.23.21</version>
88
+
<exclusions>
89
+
<exclusion>
90
+
<groupId>software.amazon.awssdk.crt</groupId>
91
+
<artifactId>aws-crt</artifactId>
92
+
</exclusion>
93
+
</exclusions>
94
+
</dependency>
95
+
96
+
<dependency>
97
+
<groupId>software.amazon.awssdk.crt</groupId>
98
+
<artifactId>aws-crt</artifactId>
99
+
<version>0.29.9</version>
100
+
<classifier>linux-x86_64</classifier>
101
+
</dependency>
102
+
</dependencies>
103
+
```
104
+
105
+
### Explicitly set the AWS CRT HTTP Client
106
+
After configuring the dependencies, it's required to explicitly specify the AWS SDK HTTP client.
107
+
Depending on the Powertools module, there is a different way to configure the SDK client.
108
+
109
+
The following example shows how to use the Lambda Powertools Parameters module while leveraging the AWS CRT Client.
public class RequestHandlerWithParams implements RequestHandler<String, String> {
121
+
122
+
// Get an instance of the SSMProvider with a custom HTTP client (aws crt).
123
+
SSMProvider ssmProvider = SSMProvider
124
+
.builder()
125
+
.withClient(
126
+
SsmClient.builder()
127
+
.httpClient(AwsCrtHttpClient.builder().build())
128
+
.build()
129
+
)
130
+
.build();
131
+
132
+
public String handleRequest(String input, Context context) {
133
+
// Retrieve a single param
134
+
String value = ssmProvider
135
+
.get("/my/secret");
136
+
// We might instead want to retrieve multiple parameters at once, returning a Map of key/value pairs
137
+
// .getMultiple("/my/secret/path");
138
+
139
+
// Return the result
140
+
return value;
141
+
}
142
+
}
143
+
```
144
+
The `aws-crt-client` was considered for adoption as 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),
145
+
but due to the impact on the developer experience it was decided to stick with the `url-connection-client`.
0 commit comments