We use machine learning technology to do auto-translation. Click "English" on top navigation bar to check Chinese version.
Announcing availability of the Amazon Web Services CRT HTTP Client in the Amazon Web Services SDK for Java 2.x
We are excited to announce the general availability (GA) of the Amazon Web Services Common Runtime (CRT) HTTP Client in the
The Amazon Web Services CRT HTTP Client is an asynchronous, non-blocking HTTP client that can be used by Amazon Web Services service clients to invoke Amazon Web Services APIs. You can use it as an alternative to the default
Faster startup time and smaller memory footprint
The Amazon Web Services CRT HTTP Client is built on top of the Java bindings of the
We have observed an improvement of up-to 76% in startup latency and a reduction of up-to 14% in memory usage in Lambda when switching from the Netty async HTTP client to the Amazon Web Services CRT HTTP client. Note that the result may vary based on the application configuration such as Lambda function memory setting. The following charts show the Lambda cold start duration and max memory usage between the Netty async HTTP client (
Lower P90 request latency
In addition to cold-start improvement, we observed an improvement of up-to 9% in P90 latency when comparing the Amazon Web Services CRT HTTP client with Netty async HTTP client.
The following chart compares the P90 latency between Amazon Web Services CRT HTTP client and the Netty async HTTP client. The test application used an S3AsyncClient to send a getObject request to download a small S3 object.
Enhanced connection management
The Amazon Web Services CRT HTTP client has a connection health option that ensures “unhealthy” connections are not being reused. Based on your use-case, you can simply set a throughput threshold that determines whether a connection is healthy. If the connection falls below the set threshold for a configured amount of time, the Amazon Web Services CRT HTTP client will treat the connection as unhealthy and close it, after the in-progress request finishes. If your application is hitting a network path that results in a dramatically slower throughput, this option will help the application recover by closing the slow connection and establishing a fresh connection for new requests.
In addition, the Amazon Web Services CRT HTTP client offers enhanced DNS load balancing support. It has an asynchronous DNS resolver that polls each requested DNS address at a regular interval and balances the traffic across multiple endpoints, which allows for automatic fail-over in the unlikely event of a slow endpoint or server outage.
Getting Started
To use the Amazon Web Services CRT HTTP client, first add the aws-crt-client dependency to your pom.xml. Search the
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-crt-client</artifactId>
<version>${aws.sdk.version}</version>
</dependency>
Then, configure your application to use the Amazon Web Services CRT HTTP client in one of the following ways.
Option 1 (preferred): Specify the CRT HTTP client through the client builder
This is the preferred option. It allows you to customize options such as max concurrency based on your use-case.
// Creating an asynchronous S3 client with a CRT HTTP client that is managed by the SDK
S3AsyncClient.builder()
.httpClientBuilder(AwsCrtAsyncHttpClient.builder()
.maxConcurrency(100))
.build();
The SDK by default includes
dependency. If you opt-in to the Amazon Web Services CRT HTTP Client in your application, it’s recommended to remove netty-nio-client
from your application to reduce the package size. Following is the sample POM file for an application that only has the CRT HTTP client in the classpath.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>${aws.java.sdk.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<exclusions>
<exclusion>
<groupId>software.amazon.awssdk</groupId>
<artifactId>netty-nio-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>aws-crt-client</artifactId>
</dependency>
</dependencies>
Option 2: Configure the HTTP client using a system property at JVM startup
The following option will create an Amazon Web Services CRT HTTP client with the default configuration.
# Specify the default asynchronous HTTP client as AwsCrtAsyncHttpClient
java -Dsoftware.amazon.awssdk.http.async.service.impl=\
software.amazon.awssdk.http.crt.AwsCrtSdkHttpService \
MyService.jar
Option 3: Configure the HTTP client using a system property in Java code.
Similar to option 2, the following option will create an Amazon Web Services CRT HTTP client with the default configuration.
System.setProperty("software.amazon.awssdk.http.async.service.impl",
"software.amazon.awssdk.http.crt.AwsCrtSdkHttpService");
Limitation
In this release,
Conclusion
In this blog post, we showed you how to get started with Amazon Web Services CRT HTTP Client. To learn more about how to configure the client, visit our
The mentioned AWS GenAI Services service names relating to generative AI are only available or previewed in the Global Regions. Amazon Web Services China promotes AWS GenAI Services relating to generative AI solely for China-to-global business purposes and/or advanced technology introduction.