通过 AWS CLI 和适用于 Java 的 SDK 开始使用 - Amazon Simple Storage Service

通过 AWS CLI 和适用于 Java 的 SDK 开始使用

通过使用 Amazon S3 on Outposts,您可以在 AWS Outposts 上创建 S3 桶,并在本地为需要本地数据访问、本地数据处理和数据驻留的应用程序轻松存储和检索对象。S3 on Outposts 提供了一个新的存储类 S3 Outposts (OUTPOSTS);该存储类使用 Amazon S3 API,并且用于在 AWS Outposts 上的多个设备和服务器之间持久冗余地存储数据。您通过 Virtual Private Cloud(VPC)使用接入点和端点连接与 Outposts 桶进行通信。您可以像在 Amazon S3 桶中一样在 Outpost 桶上使用相同的 API 和功能,包括访问策略、加密和标记。您可以通过 AWS Management Console、AWS Command Line Interface (AWS CLI)、AWS SDK 或 REST API 使用 S3 on Outposts。有关更多信息,请参阅 什么是 Amazon S3 on Outposts?

要开始使用 S3 on Outposts,您必须创建存储桶、访问点和端点。然后,您可以将对象上传到存储桶。以下示例显示如何通过 AWS CLI 和适用于 Java 的 SDK 开始使用 S3 on Outposts。要通过控制台开始使用,请参阅通过 AWS Management Console开始使用

步骤 1:创建存储桶

以下 AWS CLI 和适用于 Java 的 SDK 示例显示如何创建 S3 on Outposts 存储桶。

AWS CLI

以下示例使用 AWS CLI 创建 S3 on Outposts 存储桶 (s3-outposts:CreateBucket)。要运行此命令,请将 user input placeholders 替换为您自己的信息。

aws s3control create-bucket --bucket example-outposts-bucket --outpost-id op-01ac5d28a6a232904
SDK for Java

以下示例使用适用于 Java 的 SDK 创建 S3 on Outposts 存储桶 (s3-outposts:CreateBucket)。

import com.amazonaws.services.s3control.model.*; public String createBucket(String bucketName) { CreateBucketRequest reqCreateBucket = new CreateBucketRequest() .withBucket(bucketName) .withOutpostId(OutpostId) .withCreateBucketConfiguration(new CreateBucketConfiguration()); CreateBucketResult respCreateBucket = s3ControlClient.createBucket(reqCreateBucket); System.out.printf("CreateBucket Response: %s%n", respCreateBucket.toString()); return respCreateBucket.getBucketArn(); }

步骤 2:创建访问点

要访问 Amazon S3 on Outposts 存储桶,您必须创建和配置访问点。这些示例显示如何使用 AWS CLI 和适用于 Java 的 SDK 创建访问点。

访问点可简化对 Amazon S3 中的共享数据集的大规模数据访问管理。访问点是附加到存储桶的命名网络端点,您可以使用这些存储桶执行 Amazon S3 对象操作(如 GetObjectPutObject)。对于 S3 on Outposts,您必须使用访问点访问 Outposts 存储桶中的任何对象。访问点仅支持虚拟主机式寻址。

AWS CLI

以下 AWS CLI 示例为 Outposts 存储桶创建访问点。要运行此命令,请将 user input placeholders 替换为您自己的信息。

aws s3control create-access-point --account-id 123456789012 --name example-outposts-access-point --bucket "arn:aws:s3-outposts:region:123456789012:outpost/op-01ac5d28a6a232904/bucket/example-outposts-bucket" --vpc-configuration VpcId=example-vpc-12345
SDK for Java

以下适用于 Java 的软件开发工具包示例为 Outpost 存储桶创建访问点。要使用此示例,请将 user input placeholders 替换为您自己的信息。

import com.amazonaws.services.s3control.model.*; public String createAccessPoint(String bucketArn, String accessPointName) { CreateAccessPointRequest reqCreateAP = new CreateAccessPointRequest() .withAccountId(AccountId) .withBucket(bucketArn) .withName(accessPointName) .withVpcConfiguration(new VpcConfiguration().withVpcId("vpc-12345")); CreateAccessPointResult respCreateAP = s3ControlClient.createAccessPoint(reqCreateAP); System.out.printf("CreateAccessPoint Response: %s%n", respCreateAP.toString()); return respCreateAP.getAccessPointArn(); }

步骤 3:创建端点

要将请求路由到 Amazon S3 on Outposts 访问点,您必须创建 S3 on Outposts 端点并进行配置。为了创建端点,您需要使用服务链接建立到 Outposts 主区域的活跃连接。Outposts 上的每个 Virtual Private Cloud (VPC) 都可以有一个关联的端点。有关端点配额的更多信息,请参阅 S3 on Outposts 网络要求。您必须创建一个端点,才能访问 Outposts 桶并执行对象操作。有关更多信息,请参阅 端点

这些示例显示如何使用 AWS CLI 和适用于 Java 的 SDK 创建端点。有关创建和管理端点所需的权限的更多信息,请参阅 S3 on Outposts 端点的权限

AWS CLI

以下 AWS CLI 示例使用 VPC 资源访问类型,为 Outpost 创建端点。VPC 派生自子网。要运行此命令,请将 user input placeholders 替换为您自己的信息。

aws s3outposts create-endpoint --outpost-id op-01ac5d28a6a232904 --subnet-id subnet-8c7a57c5 --security-group-id sg-ab19e0d1

以下 AWS CLI 示例使用客户拥有的 IP 地址池(CoIP 池)访问类型为 Outpost 创建端点。要运行此命令,请将 user input placeholders 替换为您自己的信息。

aws s3outposts create-endpoint --outpost-id op-01ac5d28a6a232904 --subnet-id subnet-8c7a57c5 --security-group-id sg-ab19e0d1 --access-type CustomerOwnedIp --customer-owned-ipv4-pool ipv4pool-coip-12345678901234567
SDK for Java

以下适用于 Java 的软件开发工具包示例为 Outpost 创建端点。要使用此示例,请将 user input placeholders 替换为您自己的信息。

import com.amazonaws.services.s3outposts.AmazonS3Outposts; import com.amazonaws.services.s3outposts.AmazonS3OutpostsClientBuilder; import com.amazonaws.services.s3outposts.model.CreateEndpointRequest; import com.amazonaws.services.s3outposts.model.CreateEndpointResult; public void createEndpoint() { AmazonS3Outposts s3OutpostsClient = AmazonS3OutpostsClientBuilder .standard().build(); CreateEndpointRequest createEndpointRequest = new CreateEndpointRequest() .withOutpostId("op-0d79779cef3c30a40") .withSubnetId("subnet-8c7a57c5") .withSecurityGroupId("sg-ab19e0d1") .withAccessType("CustomerOwnedIp") .withCustomerOwnedIpv4Pool("ipv4pool-coip-12345678901234567"); // Use .withAccessType and .withCustomerOwnedIpv4Pool only when the access type is // customer-owned IP address pool (CoIP pool) CreateEndpointResult createEndpointResult = s3OutpostsClient.createEndpoint(createEndpointRequest); System.out.println("Endpoint is created and its ARN is " + createEndpointResult.getEndpointArn()); }

步骤 4:将对象上传到 S3 on Outposts 存储桶

要上传对象,请参阅将对象上传到 S3 on Outposts 存储桶