View a markdown version of this page

Usar GetBucketEncryption com o AWS SDK ou a CLI - Amazon Simple Storage Service

Usar GetBucketEncryption com o AWS SDK ou a CLI

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

.NET
SDK para .NET
nota

Há mais no GitHub. Encontre o exemplo completo e saiba como configurar e executar no AWSCode Examples Repository.

/// <summary> /// Get and print the encryption settings of a bucket. /// </summary> /// <param name="bucketName">Name of the bucket.</param> /// <returns>Async task.</returns> public static async Task GetEncryptionSettings(string bucketName) { // Check and print the bucket encryption settings. Console.WriteLine($"Getting encryption settings for bucket {bucketName}."); try { var settings = await _s3Client.GetBucketEncryptionAsync( new GetBucketEncryptionRequest() { BucketName = bucketName }); foreach (var encryptionSettings in settings?.ServerSideEncryptionConfiguration?.ServerSideEncryptionRules!) { Console.WriteLine( $"\tAlgorithm: {encryptionSettings.ServerSideEncryptionByDefault.ServerSideEncryptionAlgorithm}"); Console.WriteLine( $"\tKey: {encryptionSettings.ServerSideEncryptionByDefault.ServerSideEncryptionKeyManagementServiceKeyId}"); } } catch (AmazonS3Exception ex) { Console.WriteLine(ex.ErrorCode == "InvalidBucketName" ? $"Bucket {bucketName} was not found." : $"Unable to get bucket encryption for bucket {bucketName}, {ex.Message}"); } }
  • Para ter detalhes da API, consulte GetBucketEncryption na Referência da API do AWS SDK para .NET.

CLI
AWS CLI

Para recuperar a configuração de criptografia do lado do servidor para um bucket

O exemplo get-bucket-encryption a seguir recupera a configuração de criptografia do lado do servidor do bucket amzn-s3-demo-bucket.

aws s3api get-bucket-encryption \ --bucket amzn-s3-demo-bucket

Resultado:

{ "ServerSideEncryptionConfiguration": { "Rules": [ { "ApplyServerSideEncryptionByDefault": { "SSEAlgorithm": "AES256" } } ] } }
PowerShell
Ferramentas para PowerShell V4

Exemplo 1: este comando retorna todas as regras de criptografia do lado do servidor associadas ao bucket em questão.

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

Ferramentas para PowerShell V5

Exemplo 1: este comando retorna todas as regras de criptografia do lado do servidor associadas ao bucket em questão.

Get-S3BucketEncryption -BucketName 'amzn-s3-demo-bucket'
  • Consulte detalhes da API em GetBucketEncryption 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. Este tópico também inclui informações sobre como começar e detalhes sobre versões anteriores do SDK.