ruby/example_code/s3/s3_add_sseck_encrypt_item.rb
def run_me
  bucket_name = 'doc-example-bucket'
  object_key = 'my-file.txt'
  content_to_encrypt = 'This is the content of my-file.txt.'
  region = 'us-west-2'
  s3_client = Aws::S3::Client.new(region: region)

  # The following call generates a random AES256-GCM key. Alternatively, you can
  # provide a base64-encoded string representation of an existing key that
  # you want to use to encrypt the object. For example:#
  # encryption_key_string = 'XSiKrmzhtDKR9tTwJRSLjgwLhiMA82TC2z3GEXAMPLE='
  # encryption_key = encryption_key_string.unpack('m')[0]
  encryption_key = get_random_aes_256_gcm_key

  if customer_key_sse_encrypted_object_uploaded?(
    s3_client,
    bucket_name,
    object_key,
    content_to_encrypt,
    encryption_key
  )
    puts 'Encrypted object uploaded.'
  else
    puts 'Encrypted object not uploaded.'
  end
end
# Replace us-west-2 with the AWS Region you're using for Amazon S3.

Replace us-west-2 with the AWS Region you're using for Amazon S3.
Replace us - west - 2 with the AWS Region you ' re using for Amazon S3 .
def run_me
  bucket_name = 'doc-example-bucket'
  object_key = 'my-file.txt'
  content_to_encrypt = 'This is the content of my-file.txt.'
  region = 'us-west-2'
  s3_client = Aws::S3::Client.new(region: region)
  encryption_key = get_random_aes_256_gcm_key
  if customer_key_sse_encrypted_object_uploaded?(
    s3_client,
    bucket_name,
    object_key,
    content_to_encrypt,
    encryption_key
  )
    puts 'Encrypted object uploaded.'
  else
    puts 'Encrypted object not uploaded.'
  end
end
def run_me bucket_name = 'doc-example-bucket' object_key = 'my-file.txt' content_to_encrypt = 'This is the content of my-file.txt.' region = 'us-west-2' s3_client = Aws :: S3 :: Client . new ( region : region ) encryption_key = get_random_aes_256_gcm_key if customer_key_sse_encrypted_object_uploaded? ( s3_client , bucket_name , object_key , content_to_encrypt , encryption_key ) puts 'Encrypted object uploaded.' else puts 'Encrypted object not uploaded.' end end
Replace us-west-2 with the AWS Region you're using for Amazon S3.
Replace us - west - 2 with the AWS Region you ' re using for Amazon S3 .
# The following call generates a random AES256-GCM key. Alternatively, you can
 # provide a base64-encoded string representation of an existing key that
 # you want to use to encrypt the object. For example:#
 # encryption_key_string = 'XSiKrmzhtDKR9tTwJRSLjgwLhiMA82TC2z3GEXAMPLE='
 # encryption_key = encryption_key_string.unpack('m')[0]
