Usar GetBucketReplication com o AWS SDK ou a CLI - Exemplos de código do AWS SDK

Há mais exemplos do AWS SDK disponíveis no repositório do GitHub Documento de Exemplos do AWS SDK.

Usar GetBucketReplication com o AWS SDK ou a CLI

Os exemplos de código a seguir mostram como usar o GetBucketReplication.

CLI
AWS CLI

O seguinte comando recupera a configuração de replicação de um bucket denominado amzn-s3-demo-bucket:

aws s3api get-bucket-replication --bucket amzn-s3-demo-bucket

Saída:

{ "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" } }
Java
SDK para Java 2.x
nota

Há mais no GitHub. Encontre o exemplo completo e veja como configurar e executar no AWS Code Examples Repository.

/** * 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()); } }
PowerShell
Ferramentas para PowerShell V4

Exemplo 1: retorna as informações da configuração de replicação definida no bucket denominado “amzn-s3-demo-bucket”.

Get-S3BucketReplication -BucketName amzn-s3-demo-bucket
  • Consulte detalhes da API em GetBucketReplication na Referência de cmdlet do Ferramentas da AWS para PowerShell (V4).

Ferramentas para PowerShell V5

Exemplo 1: retorna as informações da configuração de replicação definida no bucket denominado “amzn-s3-demo-bucket”.

Get-S3BucketReplication -BucketName amzn-s3-demo-bucket
  • Consulte detalhes da API em GetBucketReplication na Referência de cmdlet do Ferramentas da AWS para PowerShell (V5).