yahia mourad
yahia mourad

Reputation: 61

Spring cloud aws set endpoint

I user Spring cloud AWS for connecte to my Amazon S3 in openStack by default the endpoint is s3.amasonaws.com I want change the endpoint because my bucket S3 us in the private cloud not in public amazon cloud.

 <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-aws</artifactId>
 </dependency>

. . . .

<dependencyManagement>
 <dependencies>
  <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-dependencies</artifactId>
    <version>${spring-cloud.version}</version>
    <type>pom</type>
    <scope>import</scope>
  </dependency>
 </dependencies>
</dependencyManagement>

.... in my application.properties

cloud.aws.stack.auto=false
cloud.aws.region.static=eu-west-3
storage.s3.accessKey=AKIAJNGI4VX4DTY4U24Q

thinks for your help.

Upvotes: 6

Views: 5809

Answers (2)

dukethrash
dukethrash

Reputation: 1529

You can use cloud.aws.s3.endpoint property to override the endpoint.

Upvotes: 2

Felipe Desiderati
Felipe Desiderati

Reputation: 2982

I had a similar problem trying to use LocalStack with S3 configured locally in my machine. As Spring Boot doesn't have an option to configure the endpoint, we had to define the bean by ourselves. Then, we just had to use the newly defined bean.

/**
 * It must be configured, if we need to upload a file using the LocakStack configuration.
 * Because of it, we must define a new client since the default one has not an option to configure the Endpoint.
 *
 * @see org.springframework.cloud.aws.context.config.annotation.ContextResourceLoaderConfiguration.Registrar#registerBeanDefinitions(AnnotationMetadata, BeanDefinitionRegistry)
 */
@Bean(name = "amazonS3Client")
public AmazonS3 amazonS3Client(AWSCredentialsProvider credentialsProvider,
                               RegionProvider regionProvider,
                               @Value("${aws.s3.default-endpoint:https://s3.amazonaws.com}") String endpoint) {

    return AmazonS3ClientBuilder.standard()
        .withCredentials(credentialsProvider)
        .withEndpointConfiguration(
            new AwsClientBuilder.EndpointConfiguration(endpoint, regionProvider.getRegion().getName()))
        .build();
}

Upvotes: 4

Related Questions