如何使用 AWS 开发工具包 V2 配置 Amazon S3 终端节点?

ara*_*ind 5 java amazon-s3 amazon-web-services

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

BasicAWSCredentials awsCredentials = new BasicAWSCredentials(Credentials.access_key, Credentials.secret_access_key);
Run Code Online (Sandbox Code Playgroud)

然后将端点设置为:

EndpointConfiguration endpoint = new EndpointConfiguration("<endpoint URL>", "<region>"); 
Run Code Online (Sandbox Code Playgroud)

然后创建客户端:

AmazonS3 s3client = AmazonS3ClientBuilder.standard()
            .withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
            .withEndpointConfiguration(endpoint)
            .build(); 
Run Code Online (Sandbox Code Playgroud)

如何使用 AWS 开发工具包 V2 设置同一客户端?

sma*_*020 9

查看这里的 Javadocs:

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();
Run Code Online (Sandbox Code Playgroud)