是否可以使用Spring Cloud AWS (Spring Cloud AWS Core / Spring Cloud AWS Context)连接到完全支持S3接口的S3 on-premise (如Minio/SwiftStack)?
简而言之,S3服务的网址需要在我的应用程序逻辑中建立框架,而不是基于区域构建默认的spring cloud AWS。
发布于 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
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
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发布于 2020-05-06 00:59:23
是的,你应该能够做到。我测试了cloudfoundry与S3兼容的blobstore MinIO作为blobstore。您可以快速安装MinIO服务器并更改端点,而不是S3。
发布于 2020-05-06 02:48:30
你可以参考下面的博客,了解如何通过minio和backend访问s3客户端。请让我知道。
https://blogs.ashrithgn.com/spring-boot-uploading-and-downloading-file-from-minio-object-store/
https://docs.min.io/docs/how-to-use-aws-sdk-for-java-with-minio-server.html
https://stackoverflow.com/questions/61605943
复制相似问题