首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否可以使用Spring Cloud AWS连接到本地S3兼容存储?

是否可以使用Spring Cloud AWS连接到本地S3兼容存储?
EN

Stack Overflow用户
提问于 2020-05-05 12:43:21
回答 3查看 907关注 0票数 2

是否可以使用Spring Cloud AWS (Spring Cloud AWS Core / Spring Cloud AWS Context)连接到完全支持S3接口的S3 on-premise (如Minio/SwiftStack)?

简而言之,S3服务的网址需要在我的应用程序逻辑中建立框架,而不是基于区域构建默认的spring cloud AWS。

EN

回答 3

Stack Overflow用户

发布于 2020-09-15 06:15:47

应用程序可以提供自己的AmazonS3 bean,配置为连接到本地S3兼容的存储服务。

这之所以有效,是因为Spring Cloud配置代码被配置为,如果应用程序已经提供了自己的AmazonS3 bean,则不创建它自己的bean。因此,如果应用程序提供了自己的AmazonS3 bean,则该bean将用作S3客户端,而不是默认的。

我使用Spring Cloud AWS在运行的应用程序中访问Amazon的AWS,并使用Dockerized MinIO进行集成测试。我已经基于sample code in MinIO's documentation配置了测试的AmazonS3 bean。这种方法也适用于将实际应用程序连接到MinIO的情况。

MinIoConfiguration.java

代码语言:javascript
复制
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MinIoConfiguration {
    @Value("${cloud.aws.credentials.accessKey}")
    private String awsAccessKey;

    @Value("${cloud.aws.credentials.secretKey}")
    private String awsSecretKey;

    @Value("${cloud.aws.region.static}")
    private String awsRegion;

    @Value("${my-app.aws.service-endpoint}")
    private String awsServiceEndpoint;

    @Bean
    public AmazonS3 amazonS3() {
        return AmazonS3Client.builder()
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(awsServiceEndpoint, awsRegion))
                .withPathStyleAccessEnabled(true)
                .withClientConfiguration(new ClientConfiguration().withSignerOverride("AWSS3V4SignerType"))
                .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(awsAccessKey, awsSecretKey)))
                .build();
    }
}

application.yml

代码语言:javascript
复制
cloud:
  aws:
    credentials:
      accessKey: MY_ACCESS_KEY
      secretKey: MY_SECRET_KEY
    region.static: us-east-1

my-app:
  aws:
    service-endpoint: https://example.invalid:9000
票数 3
EN

Stack Overflow用户

发布于 2020-05-06 00:59:23

是的,你应该能够做到。我测试了cloudfoundry与S3兼容的blobstore MinIO作为blobstore。您可以快速安装MinIO服务器并更改端点,而不是S3。

票数 0
EN

Stack Overflow用户

发布于 2020-05-06 02:48:30

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61605943

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档