Medical physicist Medical physicist - 15 days ago 5
C++ Question

AWS SDK C++: putting an object in S3 with server side encryption

It's very easy to select server side encryption in S3 when putting an object with the AWS SDK PHP:

$result = $client->putObject(array(
'Bucket' => $bucket,
'Key' => $key,
'SourceFile' => $source_file,
'ServerSideEncryption' => 'AES256'
));


Putting an object in S3 with the AWS SDK C++ looks similar to:

Aws::S3::Model::PutObjectRequest object_request;
object_request.WithBucket(bucket_name).WithKey(key_name);
auto input_data = Aws::MakeShared<Aws::FStream>(key_name.c_str(), dir_name.c_str(), std::ios_base::in);
object_request.SetBody(input_data);
auto put_object_outcome = s3_client.PutObject(object_request);


But, how can you select server side encryption with the AWS SDK C++?

Answer

Ok, I found the solution:

object_request.WithServerSideEncryption(Aws::S3::Model::ServerSideEncryption::AES256);
Comments