All Downloads are FREE. Search and download functionalities are using the official Maven repository.

driven-adapter.s3-reactive.s3-config.mustache Maven / Gradle / Ivy

Go to download

Gradle plugin to create a clean application in Java that already works, It follows our best practices!

There is a newer version: 3.20.10
Show newest version
package {{package}}.s3.config;

import {{package}}.s3.config.model.S3ConnectionProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
{{#metrics}}
import software.amazon.awssdk.metrics.MetricPublisher;
{{/metrics}}
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3AsyncClient;


import java.net.URI;

@Configuration
public class S3Config {

    {{^metrics}}
    @Profile({"dev", "cer", "pdn"})
    @Bean
    public S3AsyncClient s3AsyncClient(S3ConnectionProperties s3Properties) {
        return S3AsyncClient.builder()
                .region(Region.of(s3Properties.getRegion()))
                .build();
    }

    @Profile("local")
    @Bean
    public S3AsyncClient localS3AsyncClient(S3ConnectionProperties s3Properties) {
        return S3AsyncClient.builder()
                .region(Region.of(s3Properties.getRegion()))
                .credentialsProvider(ProfileCredentialsProvider.create("default"))
                .endpointOverride(URI.create(s3Properties.getEndpoint()))
                .build();
    }
    {{/metrics}}
    {{#metrics}}
    @Profile({"dev", "cer", "pdn"})
    @Bean
    public S3AsyncClient s3AsyncClient(S3ConnectionProperties s3Properties, MetricPublisher publisher) {
        return S3AsyncClient.builder()
                .overrideConfiguration(o -> o.addMetricPublisher(publisher))
                .region(Region.of(s3Properties.getRegion()))
                .build();
    }

    @Profile("local")
    @Bean
    public S3AsyncClient localS3AsyncClient(S3ConnectionProperties s3Properties,
                                            MetricPublisher publisher) {
        return S3AsyncClient.builder()
                .overrideConfiguration(o -> o.addMetricPublisher(publisher))
                .region(Region.of(s3Properties.getRegion()))
                .credentialsProvider(ProfileCredentialsProvider.create("default"))
                .endpointOverride(URI.create(s3Properties.getEndpoint()))
                .build();
    }
    {{/metrics}}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy