Pilih preferensi cookie Anda

Kami menggunakan cookie penting serta alat serupa yang diperlukan untuk menyediakan situs dan layanan. Kami menggunakan cookie performa untuk mengumpulkan statistik anonim sehingga kami dapat memahami cara pelanggan menggunakan situs dan melakukan perbaikan. Cookie penting tidak dapat dinonaktifkan, tetapi Anda dapat mengklik “Kustom” atau “Tolak” untuk menolak cookie performa.

Jika Anda setuju, AWS dan pihak ketiga yang disetujui juga akan menggunakan cookie untuk menyediakan fitur situs yang berguna, mengingat preferensi Anda, dan menampilkan konten yang relevan, termasuk iklan yang relevan. Untuk menerima atau menolak semua cookie yang tidak penting, klik “Terima” atau “Tolak”. Untuk membuat pilihan yang lebih detail, klik “Kustomisasi”.

Use GetBucketEncryption with an AWS SDK or CLI

Mode fokus
Use GetBucketEncryption with an AWS SDK or CLI - Amazon Simple Storage Service
Halaman ini belum diterjemahkan ke dalam bahasa Anda. Minta terjemahan

The following code examples show how to use GetBucketEncryption.

.NET
SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code 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}"); } }
CLI
AWS CLI

To retrieve the server-side encryption configuration for a bucket

The following get-bucket-encryption example retrieves the server-side encryption configuration for the bucket amzn-s3-demo-bucket.

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

Output:

{ "ServerSideEncryptionConfiguration": { "Rules": [ { "ApplyServerSideEncryptionByDefault": { "SSEAlgorithm": "AES256" } } ] } }
PowerShell
Tools for PowerShell

Example 1: This command returns all the server side encryption rules associated with the given bucket.

Get-S3BucketEncryption -BucketName 'amzn-s3-demo-bucket'
SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code 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}"); } }

For a complete list of AWS SDK developer guides and code examples, see Developing with Amazon S3 using the AWS SDKs. This topic also includes information about getting started and details about previous SDK versions.

PrivasiSyarat situsPreferensi cookie
© 2025, Amazon Web Services, Inc. atau afiliasinya. Semua hak dilindungi undang-undang.