使用 S3 on Outposts 双堆栈端点 - Amazon Simple Storage Service
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

使用 S3 on Outposts 双堆栈端点

S3 on Outposts 双堆栈端点支持通过 IPv6 和 IPv4 向 S3 on Outposts 桶发出的请求。本节介绍如何使用 S3 on Outposts 双堆栈端点。

S3 on Outposts 双堆栈端点

当您向双堆栈端点发出请求时,S3 on Outposts 桶 URL 解析为 IPv6 或 IPv4 地址。有关如何通过 IPv6 访问 S3 on Outposts 桶的更多信息,请参阅通过 IPv6 向 S3 on Outposts 发出请求

要通过双堆栈端点访问 S3 on Outposts 桶,请使用路径样式端点名称。S3 on Outposts 只支持区域双堆栈端点名称,这意味着,您必须在名称中指定区域。

对于双堆栈路径样式的 FIP 端点,请使用以下命名约定:

s3-outposts-fips.region.api.aws

对于双堆栈非 FIPS 端点,请使用以下命名约定:

s3-outposts.region.api.aws
注意

S3 on Outposts 不支持虚拟托管样式的端点名称。

从 Amazon CLI 使用双堆栈端点

本节提供用于向双堆栈端点发出请求的 Amazon CLI 命令示例。有关设置 Amazon CLI 的说明,请参阅通过 Amazon CLI 和适用于 Java 的 SDK 开始使用

在 Amazon Config 文件内的配置文件中将配置值 use_dualstack_endpoint 设置为 true,从而将 s3s3api Amazon CLI 命令发出的所有 Amazon S3 请求都定向到指定区域的双堆栈端点。您可以在配置文件或命令中使用 --region 选项指定区域。

通过 Amazon CLI 使用双堆栈端点时,仅支持 path 寻址样式。在配置文件中设置的寻址样式确定桶名称是在主机名中还是在 URL 中。有关更多信息,请参阅《Amazon CLI 用户指南》中的 s3outposts

要通过 Amazon CLI 使用双栈端点,请将 --endpoint-url 参数与 http://s3.dualstack.region.amazonaws.comhttps://s3-outposts-fips.region.api.aws 端点一起用于任何 s3controls3outposts 命令。

例如:

$ aws s3control list-regional-buckets --endpoint-url https://s3-outposts.region.api.aws

从 Amazon SDK 使用 S3 on Outposts 双堆栈端点

本节提供一些示例,介绍如何使用 Amazon SDK 来访问双堆栈端点。

Amazon SDK for Java 2.x双堆栈端点示例

以下示例显示了当使用 Amazon SDK for Java 2.x 创建 S3 on Outposts 客户端时,如何使用 S3ControlClientS3OutpostsClient 类来启用双堆栈端点。有关为 Amazon S3 on Outposts 创建和测试有效 Java 示例的说明,请参阅通过 Amazon CLI 和适用于 Java 的 SDK 开始使用

例 – 创建启用双堆栈端点的 S3ControlClient
import com.amazonaws.AmazonServiceException; import com.amazonaws.SdkClientException; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.s3control.S3ControlClient; import software.amazon.awssdk.services.s3control.model.ListRegionalBucketsRequest; import software.amazon.awssdk.services.s3control.model.ListRegionalBucketsResponse; import software.amazon.awssdk.services.s3control.model.S3ControlException; public class DualStackEndpointsExample1 { public static void main(String[] args) { Region clientRegion = Region.of("us-east-1"); String accountId = "111122223333"; String navyId = "9876543210"; try { // Create an S3ControlClient with dual-stack endpoints enabled. S3ControlClient s3ControlClient = S3ControlClient.builder() .region(clientRegion) .dualstackEnabled(true) .build(); ListRegionalBucketsRequest listRegionalBucketsRequest = ListRegionalBucketsRequest.builder() .accountId(accountId) .outpostId(navyId) .build(); ListRegionalBucketsResponse listBuckets = s3ControlClient.listRegionalBuckets(listRegionalBucketsRequest); System.out.printf("ListRegionalBuckets Response: %s%n", listBuckets.toString()); } catch (AmazonServiceException e) { // The call was transmitted successfully, but Amazon S3 on Outposts couldn't process // it, so it returned an error response. e.printStackTrace(); } catch (S3ControlException e) { // Unknown exceptions will be thrown as an instance of this type. e.printStackTrace(); } catch (SdkClientException e) { // Amazon S3 on Outposts couldn't be contacted for a response, or the client // couldn't parse the response from Amazon S3 on Outposts. e.printStackTrace(); } } }
例 – 创建启用双堆栈端点的 S3OutpostsClient
import com.amazonaws.AmazonServiceException; import com.amazonaws.SdkClientException; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.s3outposts.S3OutpostsClient; import software.amazon.awssdk.services.s3outposts.model.ListEndpointsRequest; import software.amazon.awssdk.services.s3outposts.model.ListEndpointsResponse; import software.amazon.awssdk.services.s3outposts.model.S3OutpostsException; public class DualStackEndpointsExample2 { public static void main(String[] args) { Region clientRegion = Region.of("us-east-1"); try { // Create an S3OutpostsClient with dual-stack endpoints enabled. S3OutpostsClient s3OutpostsClient = S3OutpostsClient.builder() .region(clientRegion) .dualstackEnabled(true) .build(); ListEndpointsRequest listEndpointsRequest = ListEndpointsRequest.builder().build(); ListEndpointsResponse listEndpoints = s3OutpostsClient.listEndpoints(listEndpointsRequest); System.out.printf("ListEndpoints Response: %s%n", listEndpoints.toString()); } catch (AmazonServiceException e) { // The call was transmitted successfully, but Amazon S3 on Outposts couldn't process // it, so it returned an error response. e.printStackTrace(); } catch (S3OutpostsException e) { // Unknown exceptions will be thrown as an instance of this type. e.printStackTrace(); } catch (SdkClientException e) { // Amazon S3 on Outposts couldn't be contacted for a response, or the client // couldn't parse the response from Amazon S3 on Outposts. e.printStackTrace(); } } }

如果要在 Windows 上使用 Amazon SDK for Java 2.x,可能必须设置以下 Java 虚拟机(JVM)属性:

java.net.preferIPv6Addresses=true