documents/aws-doc-sdk-examples/ruby/example_code/s3/s3_add_cskms_encrypt_item.rb
# Uploads an encrypted object to an Amazon S3 bucket.
#
# Prerequisites:
#
# - An Amazon S3 bucket.
# - An encrypted object to upload to the bucket.
#
# @param s3_encryption_client [Aws::S3::EncryptionV2::Client]
#   An initialized Amazon S3 V2 encryption client.
# @param bucket_name [String] The name of the bucket.
# @param object_key [String] The name of the object to upload.
# @param object_content [String] The content of the object to upload.
# @return [Boolean] true if the object was encrypted and uploaded;
#   otherwise, false.
# @example
#   s3_encryption_client = Aws::S3::EncryptionV2::Client.new(
#     region: 'us-east-1',
#     kms_key_id: '9041e78c-7a20-4db3-929e-828abEXAMPLE',
#     key_wrap_schema: :kms_context,
#     content_encryption_schema: :aes_gcm_no_padding,
#     security_profile: :v2
#   )
#   if encrypted_object_uploaded?(
#     s3_encryption_client,
#     'doc-example-bucket',
#     'my-file.txt',
#     'This is the content of my-file.txt.'
#   )
#     puts 'Uploaded.'
#   else
#     puts 'Not uploaded.'
#   end
Uploads an encrypted object to an Amazon S3 bucket.
Prerequisites.

An Amazon S3 bucket.
An encrypted object to upload to the bucket.
Uploads an encrypted object to an Amazon S3 bucket . Prerequisites . An Amazon S3 bucket . An encrypted object to upload to the bucket .
def encrypted_object_uploaded?(
  s3_encryption_client,
  bucket_name,
  object_key,
  object_content
)
  s3_encryption_client.put_object(
    bucket: bucket_name,
    key: object_key,
    body: object_content
  )
  return true
rescue StandardError => e
  puts "Error uploading object: #{e.message}"
  return false
end
def encrypted_object_uploaded? ( s3_encryption_client , bucket_name , object_key , object_content ) s3_encryption_client . put_object ( bucket : bucket_name , key : object_key , body : object_content ) return true rescue StandardError => e puts "Error uploading object: #{e.message}" return false end
Uploads an encrypted object to an Amazon S3 bucket.
Uploads an encrypted object to an Amazon S3 bucket .
true if the object was encrypted and uploaded; otherwise, false.
true if the object was encrypted and uploaded ; otherwise false .
Boolean
s3_encryption_client
An initialized Amazon S3 V2 encryption client.
An initialized Amazon S3 V2 encryption client .
bucket_name
The name of the bucket.
The name of the bucket .
object_key
The name of the object to upload.
The name of the object to upload .
object_content
The content of the object to upload.
The content of the object to upload .
example
s3_encryption_client = Aws::S3::EncryptionV2::Client.new( region: 'us-east-1', kms_key_id: '9041e78c-7a20-4db3-929e-828abEXAMPLE', key_wrap_schema: :kms_context, content_encryption_schema: :aes_gcm_no_padding, security_profile: :v2 ) if encrypted_object_uploaded?( s3_encryption_client, 'doc-example-bucket', 'my-file.txt', 'This is the content of my-file.txt.' ) puts 'Uploaded.' else puts 'Not uploaded.' end
s3_encryption_client = Aws :: S3 :: EncryptionV2 :: Client . new ( region : ' us - east - 1 ' kms_key_id : ' 9041e78c - 7a20 - 4db3 - 929e - 828abEXAMPLE ' key_wrap_schema : : kms_context content_encryption_schema : : aes_gcm_no_padding security_profile : : v2 ) if encrypted_object_uploaded? ( s3_encryption_client ' doc - example - bucket ' ' my - file . txt ' ' This is the content of my - file . txt . ' ) puts ' Uploaded . ' else puts ' Not uploaded . ' end