Use GetBucketEncryption
with an Amazon SDK or CLI
The following code examples show how to use GetBucketEncryption
.
- .NET
-
- Amazon SDK for .NET
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon 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 API details, see GetBucketEncryption in Amazon SDK for .NET API Reference.
-
- CLI
-
- Amazon 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 bucketamzn-s3-demo-bucket
.aws s3api get-bucket-encryption \ --bucket
amzn-s3-demo-bucket
Output:
{ "ServerSideEncryptionConfiguration": { "Rules": [ { "ApplyServerSideEncryptionByDefault": { "SSEAlgorithm": "AES256" } } ] } }
-
For API details, see GetBucketEncryption
in Amazon CLI Command Reference.
-
- PowerShell
-
- Tools for PowerShell V4
-
Example 1: This command returns all the server side encryption rules associated with the given bucket.
Get-S3BucketEncryption -BucketName 'amzn-s3-demo-bucket'
-
For API details, see GetBucketEncryption
in Amazon Tools for PowerShell Cmdlet Reference (V4).
-
For a complete list of Amazon SDK developer guides and code examples, see Developing with Amazon S3 using the Amazon SDKs. This topic also includes information about getting started and details about previous SDK versions.