Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I enable s3 bucket Default Encryption programmatically with AWSSDK?

Tags:

amazon-s3

I am trying to enable default encryption for s3 Bucket programmatically. Following is not working no errors as well. Anybody know the reason for this ?

        private async Task<PutBucketEncryptionResponse> EnableServerSideEncriptionAsync(string bucketName)
    {
        return await S3Client.PutBucketEncryptionAsync(new PutBucketEncryptionRequest
        {
            BucketName = bucketName,
            ServerSideEncryptionConfiguration = new ServerSideEncryptionConfiguration()
            {
                ServerSideEncryptionRules = new List<ServerSideEncryptionRule>()
                {
                    new ServerSideEncryptionRule()
                    {
                        ServerSideEncryptionByDefault = new ServerSideEncryptionByDefault()
                        {
                            ServerSideEncryptionAlgorithm = ServerSideEncryptionMethod.AES256
                        }

                    }
                }
            }
        });
    }
like image 817
DineshNS Avatar asked Mar 08 '26 20:03

DineshNS


1 Answers

I tried it using the AWS Command-Line Interface (CLI) to see what would happen.

I created a new bucket, and ran:

aws s3api put-bucket-encryption --bucket my-bucket --server-side-encryption-configuration '{"Rules": [{"ApplyServerSideEncryptionByDefault": {"SSEAlgorithm": "AES256"}}]}'

I then went to the bucket in the Amazon S3 console, clicked the Properties tab and the Default Encryption box displayed: AES-256

S3 Bucket default encryption

like image 185
John Rotenstein Avatar answered Mar 11 '26 16:03

John Rotenstein