ruby/example_code/s3/s3_add_csaes_encrypt_item.rb
def run_me
  bucket_name = 'doc-example-bucket'
  object_key = 'my-file.txt'
  region = 'us-west-2'
  object_content = File.read(object_key)

  # 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

  # Note that in the following call:
  # - key_wrap_schema must be aes_gcm for symmetric keys.
  # - To allow reading and decrypting objects that are encrypted by the
  #   Amazon S3 V1 encryption client instead, use :v2_and_legacy instead of :v2.
  s3_encryption_client = Aws::S3::EncryptionV2::Client.new(
    region: region,
    encryption_key: encryption_key,
    key_wrap_schema: :aes_gcm,
    content_encryption_schema: :aes_gcm_no_padding,
    security_profile: :v2
  )

  if encrypted_object_uploaded?(
    s3_encryption_client,
    bucket_name,
    object_key,
    object_content
  )
    puts 'Uploaded.'
  else
    puts 'Not uploaded.'
  end
end
# Full example call:
# Replace us-west-2 with the AWS Region you're using for Amazon S3.

Full example call:
Replace us-west-2 with the AWS Region you're using for Amazon S3.
Full example call : 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'
  region = 'us-west-2'
  object_content = File.read(object_key)
  encryption_key = get_random_aes_256_gcm_key
  s3_encryption_client = Aws::S3::EncryptionV2::Client.new(
    region: region,
    encryption_key: encryption_key,
    key_wrap_schema: :aes_gcm,
    content_encryption_schema: :aes_gcm_no_padding,
    security_profile: :v2
  )
  if encrypted_object_uploaded?(
    s3_encryption_client,
    bucket_name,
    object_key,
    object_content
  )
    puts 'Uploaded.'
  else
    puts 'Not uploaded.'
  end
end
def run_me bucket_name = 'doc-example-bucket' object_key = 'my-file.txt' region = 'us-west-2' object_content = File . read ( object_key ) encryption_key = get_random_aes_256_gcm_key s3_encryption_client = Aws :: S3 :: EncryptionV2 :: Client . new ( region : region , encryption_key : encryption_key , key_wrap_schema : :aes_gcm , content_encryption_schema : :aes_gcm_no_padding , security_profile : :v2 ) if encrypted_object_uploaded? ( s3_encryption_client , bucket_name , object_key , object_content ) puts 'Uploaded.' else puts 'Not uploaded.' end end
Full example call:
Replace us-west-2 with the AWS Region you're using for Amazon S3.
Full example call : 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]
 # Note that in the following call:
 # - key_wrap_schema must be aes_gcm for symmetric keys.
 # - To allow reading and decrypting objects that are encrypted by the
 #   Amazon S3 V1 encryption client instead, use :v2_and_legacy instead of :v2.
