Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejwalkowiak committed Sep 23, 2024
1 parent 6b1a097 commit f4ebf4d
Showing 1 changed file with 36 additions and 25 deletions.
61 changes: 36 additions & 25 deletions docs/src/main/asciidoc/core.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -214,38 +214,49 @@ To simplify using services with AWS compatible APIs, or running applications aga

=== Customizing AWS Clients

To configure an AWS client with custom HTTP client or `ClientOverrideConfiguration`, define a bean of type `AwsClientConfigurer` with a type parameter indicating configured client builder.
Properties cover the most common configuration needs. When more advanced configuration is required, Spring Cloud AWS offers a set of customizer beans that can be implemented to customize AWS clients.

There are two types of AWS clients - synchronous and asynchronous. Each Spring Cloud AWS integration use one or the other type:

[cols="2*", options="header"]
|===
|client type
|integrations

|synchronous
|DynamoDB, SES, SNS, Parameter Store, Secrets Manager, S3

|asynchronous
|SQS, CloudWatch
|===

To customize every synchronous client, provide a bean of type `AwsSyncClientCustomizer`. For example:

[source,java,indent=0]
----
import io.awspring.cloud.autoconfigure.core.AwsClientCustomizer;
import org.springframework.context.annotation.Bean;
import io.awspring.cloud.autoconfigure.AwsSyncClientCustomizer;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.http.SdkHttpClient;
import software.amazon.awssdk.http.apache.ApacheHttpClient;
import software.amazon.awssdk.services.sns.SnsClientBuilder;
@Bean
AwsSyncClientCustomizer awsSyncClientCustomizer() {
return builder -> {
builder.httpClient(ApacheHttpClient.builder().connectionTimeout(Duration.ofSeconds(1)).build());
};
}
----

import java.time.Duration;
To customize every asynchronous client, provide a bean of type `AwsAsyncClientCustomizer`. For example:

@Configuration
class S3AwsClientConfigurerConfiguration {
[source,java,indent=0]
----
@Bean
AwsAsyncClientCustomizer awsAsyncClientCustomizer() {
return builder -> {
builder.httpClient(NettyNioAsyncHttpClient.builder().connectionTimeout(Duration.ofSeconds(1)).build());
};
}
----

@Bean
AwsClientCustomizer<S3ClientBuilder> s3ClientBuilderAwsClientConfigurer() {
return new S3AwsClientClientConfigurer();
}
There can be multiple customizer beans present in single application context and all of them will be used to configure AWS clients. If order of customizer matters, use `@Order` annotation on customizer beans.

static class S3AwsClientClientConfigurer implements AwsClientCustomizer<S3ClientBuilder> {
@Override
public ClientOverrideConfiguration overrideConfiguration() {
return ClientOverrideConfiguration.builder().apiCallTimeout(Duration.ofMillis(500)).build();
}

@Override
public SdkHttpClient httpClient() {
return ApacheHttpClient.builder().connectionTimeout(Duration.ofMillis(1000)).build();
}
}
}
----

0 comments on commit f4ebf4d

Please sign in to comment.