AWS文件開發套件範例
將 GetBucketReplication 與 AWS SDK 或 CLI 搭配使用
下列程式碼範例示範如何使用 GetBucketReplication。
- CLI
-
- AWS CLI
-
下列命令會擷取名為
amzn-s3-demo-bucket之儲存貯體的複寫組態:aws s3api get-bucket-replication --bucketamzn-s3-demo-bucket輸出:
{ "ReplicationConfiguration": { "Rules": [ { "Status": "Enabled", "Prefix": "", "Destination": { "Bucket": "arn:aws:s3:::amzn-s3-demo-bucket-backup", "StorageClass": "STANDARD" }, "ID": "ZmUwNzE4ZmQ4tMjVhOS00MTlkLOGI4NDkzZTIWJjNTUtYTA1" } ], "Role": "arn:aws:iam::123456789012:role/s3-replication-role" } }-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 GetBucketReplication
。
-
- Java
-
- SDK for Java 2.x
-
注意
GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 /** * Retrieves the replication details for the specified S3 bucket. * * @param s3Client the S3 client used to interact with the S3 service * @param sourceBucketName the name of the S3 bucket to retrieve the replication details for * * @throws S3Exception if there is an error retrieving the replication details */ public static void getReplicationDetails(S3Client s3Client, String sourceBucketName) { GetBucketReplicationRequest getRequest = GetBucketReplicationRequest.builder() .bucket(sourceBucketName) .build(); try { ReplicationConfiguration replicationConfig = s3Client.getBucketReplication(getRequest).replicationConfiguration(); ReplicationRule rule = replicationConfig.rules().get(0); System.out.println("Retrieved destination bucket: " + rule.destination().bucket()); System.out.println("Retrieved priority: " + rule.priority()); System.out.println("Retrieved source-bucket replication rule status: " + rule.status()); } catch (S3Exception e) { System.err.println("Failed to retrieve replication details: " + e.awsErrorDetails().errorMessage()); } }-
如需 API 詳細資訊,請參閱《AWS SDK for Java 2.x API 參考》中的 GetBucketReplication。
-
- PowerShell
-
- Tools for PowerShell V4
-
範例 1:傳回在名為 'amzn-s3-demo-bucket' 的儲存貯體上設定的複寫組態資訊。
Get-S3BucketReplication -BucketName amzn-s3-demo-bucket-
如需 API 詳細資訊,請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》中的 GetBucketReplication。
-
- Tools for PowerShell V5
-
範例 1:傳回在名為 'amzn-s3-demo-bucket' 的儲存貯體上設定的複寫組態資訊。
Get-S3BucketReplication -BucketName amzn-s3-demo-bucket-
如需 API 詳細資訊,請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》中的 GetBucketReplication。
-
GetBucketPolicyStatus
GetBucketRequestPayment