6

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.

yahia mourad
  • 61
  • 1
  • 2

2 Answers2

4

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();
}
Felipe Desiderati
  • 2,414
  • 3
  • 24
  • 42
2

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

dukethrash
  • 1,449
  • 4
  • 15
  • 25
  • There is no `cloud.aws.s3.endpoint` property in version 2.2.6.RELEASE. Not sure what version you used. – Le Quang Nhan Sep 10 '21 at 10:11
  • Well, the documentation says `cloud.aws.s3.endpoint` which "Overrides the default endpoint". https://docs.awspring.io/spring-cloud-aws/docs/current/reference/html/appendix.html – Robert Strauch Jul 28 '22 at 10:09
  • but the `.endpoint` is actually not work, even for `cloud.aws.sqs.endpoint`, test on spring version 2.7.2. – Jie Wang Aug 24 '22 at 02:41