Skip to content

Latest commit

 

History

History
162 lines (116 loc) · 3.87 KB

File metadata and controls

162 lines (116 loc) · 3.87 KB

Client configuration of AWS SDK for Java v2

Configuration properties

Spring configuration property name for AWS SDK for Java v2 starts with aws2.<service-name>.

How to set region?

Set aws2.<service-name>.region as the property of Spring Boot.

Configuration example for DynamoDB

DynamoDbClient dynamoDB = DynamoDbClient.builder()
		.region(Region.EU_CENTRAL_1)
		.build();

The DynamoDB client equivalent to the above can be registered as follows:

aws2.dynamodb.region=eu-central-1
@Configuration
@EnableAwsClientV2(DynamoDbClient.class)
static class ExampleRegionConfiguration {
}

How to set endpoint?

Set aws2.<service-name>.endpoint as the property of Spring Boot.

Configuration example for SNS

SnsClient snsClient = SnsClient.builder()
		.endpointOverride(URI.create("http://localhost:4569"))
		.build();

The SNS client equivalent to the above can be registered as follows:

aws2.sns.endpoint=http://localhost:4569
@Configuration
@EnableAwsClientV2(SnsClient.class)
static class ExampleEndpointConfiguration {
}

Hot to set AwsCredentialsProvider?

Set aws2.<service-name>.credentials-provider-bean-name as the property of Spring Boot. It is required to register AwsCredentialsProvider bean.

Configuration example for SQS

StaticCredentialsProvider credProvider = StaticCredentialsProvider
		.create(AwsBasicCredentials
				.create("...", "..."));
SqsClient sqsClient = SqsClient.builder()
		.credentialsProvider(credProvider)
		.build();

The SQS client equivalent to the above can be registered as follows:

aws2.sqs.credentials-provider-bean-name=sqsCredentialsProvider
@Configuration
@EnableAwsClientV2(SqsClient.class)
static class ExampleCredentialsProviderConfiguration {
	
	@Bean
	public AwsCredentialsProvider sqsCredentialsProvider() {
		return StaticCredentialsProvider
				.create(AwsBasicCredentials.create("...", "..."));
	}
}

How to set SdkHttpClient.Builder or SdkAsyncHttpClient.Builder?

Set aws2.<service-name>.http-client-builder-bean-name as the property of Spring Boot. It is required to register SdkHttpClient.Builder bean for sync-client. If you want to register async-client, you should register SdkAsyncHttpClient.Builder bean.

Amazon SES に対する設定例

SdkHttpClient.Builder builder = ApacheHttpClient.builder()
		.connectionTimeout(Duration.ofMinutes(2500))
		.socketTimeout(Duration.ofSeconds(25));
SesClient sqsClient = SesClient.builder()
		.httpClientBuilder(builder)
		.build();

The SES client equivalent to the above can be registered as follows:

aws2.ses.http-client-builder-bean-name=sesHttpClientBuilder
@Configuration
@EnableAwsClientV2(SesClient.class)
static class ExampleHttpClientBuilderConfiguration {
	
	@Bean
	public SdkHttpClient.Builder sesHttpClientBuilder() {
		return ApacheHttpClient.builder()
				.connectionTimeout(Duration.ofMillis(2500))
				.socketTimeout(Duration.ofSeconds(25));
	}
}

How to configure async client?

Set aws2.<service-name>-async.* as the property of Spring Boot.

aws2.<service-name>.* does not affect to async client configuration.

Configuration example for SQS sync / async clients

aws2.sqs.client.region=us-east-1
aws2.sqs-async.region=eu-central-1

In this case, the region for SqsClient is us-east-1, and the region for SqsAsyncClient is eu-central-1.

How do you set S3Configuration for S3ClientBuilders?

Set aws2.s3.* as the property of Spring Boot.

Example of S3Configuration setting for S3

aws2.s3.path-style-access-enabled=true
aws2.s3.chunked-encoding-enabled=true
aws2.s3.accelerate-mode-enabled=false
aws2.s3.dualstack-enabled=true
aws2.s3.checksum-validation-enabled=true

For details, see the javadoc of S3Configuration.