繁体   English   中英

如何使用 AWS SDK V2 为 Amazon S3 配置终端节点?

[英]How do you configure the endpoint for Amazon S3 by using the AWS SDK V2?

在 AWS SDK V1 中,我将我的凭据设置为:

BasicAWSCredentials awsCredentials = new BasicAWSCredentials(Credentials.access_key, Credentials.secret_access_key);

然后将端点设置为:

EndpointConfiguration endpoint = new EndpointConfiguration("<endpoint URL>", "<region>"); 

然后将客户端创建为:

AmazonS3 s3client = AmazonS3ClientBuilder.standard()
            .withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
            .withEndpointConfiguration(endpoint)
            .build(); 

如何使用 AWS SDK V2 设置同一个客户端?

在此处查看 Javadoc:

https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/core/client/builder/SdkClientBuilder.html#endpointOverride-java.net.URI-

看:

端点覆盖

端点覆盖(URI端点覆盖)

配置 SDK 应与之通信的端点。 **

看起来您可以创建一个URI对象并在创建服务客户端时传递它

URI myURI = new URI("<endpoint URL>");

  Region region = Region.US_EAST_1;
  S3Client s3 = S3Client.builder()
                .region(region)
                .endpointOverride(myURI)
                .build();

如果您想将 Cloudflare R2 与 1.12.xu 一起使用,需要将端点指定为“自动”小写:

  AmazonS3 client = AmazonS3ClientBuilder.standard()
                    .withCredentials(
                            new AWSStaticCredentialsProvider(
                                    new BasicAWSCredentials(
                                            ACCESS_KEY_ID, SECRET_ACCESS_KEY)))
                    .withEndpointConfiguration(
                            new AwsClientBuilder.EndpointConfiguration("https://<accountid>.r2.cloudflarestorage.com, "auto"))
                    .build();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM