Here is the process to encrypt AWS S3 objects using KMS - CMK from Lambda in .Net:
Create a KMS - CMK key in AWS console or using AWS SDK.
Create an S3 bucket or use an existing bucket.
Create a Lambda function using AWS Console or using the AWS SDK.
Configure the Lambda function to access the S3 bucket and KMS - CMK.
Write the Lambda function code to encrypt the S3 object using KMS.
Test the Lambda function by executing it.
Verify that the Lambda function has encrypted the S3 object using KMS - CMK.
Code example:
public static async Task<GetObjectResponse> GetS3Object(string key)
{
using (var s3Client = new AmazonS3Client())
{
var request = new GetObjectRequest
{
BucketName = "my-bucket",
Key = key
};
var response = await s3Client.GetObjectAsync(request);
return response;
}
}
public static async Task<PutObjectResponse> PutS3Object(string key, string body)
{
using (var s3Client = new AmazonS3Client())
using (var kmsClient = new AmazonKeyManagementServiceClient())
{
var kmsRequest = new GenerateDataKeyRequest
{
KeyId = "my-kms-key-id",
KeySpec = DataKeySpec.AES_256
};
var kmsResponse = await kmsClient.GenerateDataKeyAsync(kmsRequest);
var request = new PutObjectRequest
{
BucketName = "my-bucket",
Key = key,
InputStream = new MemoryStream(Encoding.UTF8.GetBytes(body)),
ServerSideEncryptionMethod = ServerSideEncryptionMethod.AwsKms,
ServerSideEncryptionKeyManagementServiceKeyId = kmsResponse.KeyId
};
var response = await s3Client.PutObjectAsync(request);
return response;
}
}
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-13 16:02:52 +0000
Seen: 9 times
Last updated: May 13 '23
What is the process for altering svn branches with git-svn?
What is the process to italicize certain keywords in visual studio code?
What is the process for developing a JTable that has both row and column headers?
What is the process for removing a dat.GUI element?
How to solve the issue "process is running" in Visual Studio Debugging?
What is the process of moving information from one tab to another in Excel by transposing it?
What is the process of dividing the WSD dataset (in CSV format) into tokens called?
What is the process of uploading a file using NextJS and formidable?
What is the process for using pnpm to build a single workspace only?