

# Usar `GetBucketReplication` com o AWS SDK ou a CLI
<a name="s3_example_s3_GetBucketReplication_section"></a>

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}}
```
Resultado:  

```
{
    "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"
    }
}
```
+  Consulte detalhes da API em [GetBucketReplication](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/get-bucket-replication.html) na *Referência de comandos da AWS CLI*. 

------
#### [ Java ]

**SDK para Java 2.x**  
 Há mais no GitHub. Encontre o exemplo completo e saiba como configurar e executar no [AWSCode Examples Repository](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javav2/example_code/s3#code-examples). 

```
    /**
     * 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());
        }
    }
```
+  Consulte detalhes da API em [GetBucketReplication](https://docs.aws.amazon.com/goto/SdkForJavaV2/s3-2006-03-01/GetBucketReplication) na *Referência de API do AWS SDK for Java 2.x*. 

------
#### [ 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](https://docs.aws.amazon.com/powershell/v4/reference) 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](https://docs.aws.amazon.com/powershell/v5/reference) na *Referência de cmdlet do Ferramentas da AWS para PowerShell (V5)*. 

------

Para ver uma lista completa dos guias de desenvolvedor e exemplos de código do SDK da AWS, consulte [Desenvolvimento com o Amazon S3 usando AWS SDKs](sdk-general-information-section.md). Este tópico também inclui informações sobre como começar e detalhes sobre versões anteriores do SDK.