我在openStack中使用Spring cloud AWS连接到我亚马逊S3,默认情况下,端点是s3.amasonaws.com,我想更改端点,因为我的存储桶S3我们在私有云中,而不是在公共云中。
<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>……在我的application.properties
cloud.aws.stack.auto=false
cloud.aws.region.static=eu-west-3
storage.s3.accessKey=AKIAJNGI4VX4DTY4U24Q想着你的帮助。
发布于 2019-11-29 04:44:22
在我的机器上本地配置了S3的情况下,我尝试使用LocalStack时遇到了类似的问题。由于Spring Boot没有配置端点的选项,因此我们必须自己定义bean。然后,我们只需使用新定义的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();
}发布于 2021-09-01 17:57:54
可以使用cloud.aws.s3.endpoint属性重写终结点。
https://stackoverflow.com/questions/51235554
复制相似问题