ruby/example_code/s3/s3-ruby-example-get-cspk-item.rb
#
# Prerequisites:
#
# - An Amazon S3 bucket.
# - An object in this bucket.
#
# @param s3_encryption_client [Aws::S3::EncryptionV2::Client] An initialized
#   Amazon S3 encryption client.
# @param bucket_name [String] The bucket's name.
# @param object_key [String] The name of the object.
# @return [String] The object's content; otherwise, information about the
#   failed download operation.
# @example
#   puts download_object_with_private_key_encryption(
#     Aws::S3::EncryptionV2::Client.new(
#       encryption_key: OpenSSL::PKey::RSA.new(File.read('my-private-key.pem')),
#       key_wrap_schema: :rsa_oaep_sha1,
#       content_encryption_schema: :aes_gcm_no_padding,
#       security_profile: :v2,
#       region: 'us-west-2'
#     ),
#     'doc-example-bucket',
#     'my-file.txt'
#   )

An Amazon S3 bucket.
An object in this bucket.
An Amazon S3 bucket . An object in this bucket .
def download_object_with_private_key_encryption(
  s3_encryption_client,
  bucket_name,
  object_key
)
  response = s3_encryption_client.get_object(
    bucket: bucket_name,
    key: object_key
  )
  return response.body.read
rescue StandardError => e
  puts "Error downloading object: #{e.message}"
end
def download_object_with_private_key_encryption ( s3_encryption_client , bucket_name , object_key ) response = s3_encryption_client . get_object ( bucket : bucket_name , key : object_key ) return response . body . read rescue StandardError => e puts "Error downloading object: #{e.message}" end
Prerequisites:
 An Amazon S3 bucket.
Prerequisites : An Amazon S3 bucket .
The object's content; otherwise, information about the failed download operation.
The object ' s content ; otherwise information about the failed download operation .
String
s3_encryption_client
An initialized Amazon S3 encryption client.
An initialized Amazon S3 encryption client .
bucket_name
The bucket's name.
The bucket ' s name .
object_key
The name of the object.
The name of the object .
example
puts download_object_with_private_key_encryption( Aws::S3::EncryptionV2::Client.new( encryption_key: OpenSSL::PKey::RSA.new(File.read('my-private-key.pem')), key_wrap_schema: :rsa_oaep_sha1, content_encryption_schema: :aes_gcm_no_padding, security_profile: :v2, region: 'us-west-2' ), 'doc-example-bucket', 'my-file.txt' )
puts download_object_with_private_key_encryption ( Aws :: S3 :: EncryptionV2 :: Client . new ( encryption_key : OpenSSL :: PKey :: RSA . new ( File . read ( ' my - private - key . pem ' )) key_wrap_schema : : rsa_oaep_sha1 content_encryption_schema : : aes_gcm_no_padding security_profile : : v2 region : ' us - west - 2 ' ) ' doc - example - bucket ' ' my - file . txt ' )