使用 AWS CLI 和 SDK for Java 開始使用 - Amazon Simple Storage Service

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 AWS CLI 和 SDK for Java 開始使用

使用 Outposts 上的 Amazon S3,您可以在 Outposts 上建立 S3 儲存貯體,並輕鬆地在現場部署存放和擷取物件,以供需要本機資料存取、本機資料處理和資料存放區的應用程式使用。 AWS Outposts 上的 S3 提供新的儲存類別 S3 Outposts (OUTPOSTS),該類別使用 Amazon S3 API,其設計用於在您的多個裝置和伺服器上持久且冗餘地存放資料。 AWS Outposts您可以使用存取點和透過 Virtual Private Cloud (VPC) 的端點連線,與您的 Outpost 儲存貯體進行通訊。就像在 Amazon S3 儲存貯體一樣,您在 Outpost 儲存貯體上可以使用同樣的 API 和功能,包括存取政策、加密和標記。您可以透過 AWS Management Console、 AWS Command Line Interface (AWS CLI)、 AWS 開發套件或 REST API 在 Outposts 上使用 S3。如需詳細資訊,請參閱 什麼是 Amazon S3 on Outposts?

若要開始使用 S3 on Outposts,您必須建立儲存貯體、存取點和端點。接著,您可以將物件上傳至您的儲存貯體。下列範例說明如何使用 AWS CLI 和 SDK for Java,在 Outposts 上開始使用 S3。若要開始使用主控台,請參閱 使用 AWS Management Console 開始使用

步驟 1:建立儲存貯體

以下 AWS CLI 和 SDK for Java 示例向您展示瞭如何在 Outposts 存儲桶上創建 S3。

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 的開發套件建立 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 儲存貯體中的任何物件。存取點僅支援 virtual-host-style 定址。

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 的開發套件範例建立 Outposts 儲存貯體的存取點。若要使用此範例,請以您自己的資訊取代 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 Outpost 存取點,您必須建立和設定 S3 on Outposts 端點。若要建立端點,您需要與 Outposts 主要區域的服務連結有效連接。Outpost 上的每個 Virtual Private Cloud (VPC) 可以有一個相關聯的端點。如需端點配額的詳細資訊,請參閱 S3 on Outposts 網路需求。您必須建立端點,才能存取您的 Outposts 儲存貯體並執行物件操作。如需詳細資訊,請參閱 端點

這些範例說明如何使用 AWS CLI 和 SDK for Java 來建立端點。如需建立和管理端點所需許可的詳細資訊,請參閱 適用於 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 的開發套件範例建立 Outposts 的端點。若要使用此範例,請以您自己的資訊取代 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 儲存貯體

若要上傳物件,請參閱 將對象上傳到 Outposts 存儲桶上的 S3