ruby/example_code/s3/s3-ruby-example-set-item-props.rb
# Copies an object from one Amazon Simple Storage Service (Amazon S3)
#   bucket to another. You can also set an access control list
#   (ACL) and an S3 storage class on the copied object.
#
# Prerequisites:
#
# - A source S3 bucket and a target S3 bucket.
# - An object in the source bucket to copy.
#
# @param s3_client [Aws::S3::Client] An initialized S3 client.
# @param source_object_path [String] The path and file name of the
#   object to copy.
# @param target_bucket_name [String] The name of the destination bucket.
# @param target_object_path [String] The path and file name of the
#   copied object in the destination bucket.
# @param canned_acl [String] A predetermined ACL. Allowed values include
#   'private', 'public-read', 'public-read-write', 'authenticated-read',
#   'aws-exec-read', 'bucket-owner-read', and 'bucket-owner-full-control'.
#   If not specified, the default is 'private'.
# @param storage_class [String] The S3 storage class for the copied object.
#   Allowed values include 'STANDARD', 'REDUCED_REDUNDANCY', 'STANDARD_IA',
#   'ONEZONE_IA', 'INTELLIGENT_TIERING', 'GLACIER', and 'DEEP_ARCHIVE'.
#   If not specified, the default is 'STANDARD'.
# @return [Boolean] true if the object was copied; otherwise, false.
# @example
#   exit 1 unless object_copied_with_additional_properties?(
#     Aws::S3::Client.new(region: 'us-east-1'),
#     'doc-example-bucket/my-file.txt',
#     'doc-example-bucket1',
#     'copied-files/my-copied-file.txt',
#     'bucket-owner-read',
#     'STANDARD_IA'
#   )

Copies an object from one Amazon Simple Storage Service (Amazon S3)
bucket to another. You can also set an access control list
(ACL) and an S3 storage class on the copied object.



A source S3 bucket and a target S3 bucket.
An object in the source bucket to copy.
Copies an object from one Amazon Simple Storage Service ( Amazon S3 ) bucket to another . You can also set an access control list ( ACL ) and an S3 storage class on the copied object . A source S3 bucket and a target S3 bucket . An object in the source bucket to copy .
def object_copied_with_additional_properties?(
  s3_client,
  source_object_path,
  target_bucket_name,
  target_object_path,
  canned_acl = 'private',
  storage_class = 'STANDARD'
)
  s3_client.copy_object(
    bucket: target_bucket_name,
    copy_source: source_object_path,
    key: target_object_path,
    acl: canned_acl,
    storage_class: storage_class
  )
  return true
rescue StandardError => e
  puts "Error copying object: #{e.message}"
  return false
end
def object_copied_with_additional_properties? ( s3_client , source_object_path , target_bucket_name , target_object_path , canned_acl = 'private' , storage_class = 'STANDARD' ) s3_client . copy_object ( bucket : target_bucket_name , copy_source : source_object_path , key : target_object_path , acl : canned_acl , storage_class : storage_class ) return true rescue StandardError => e puts "Error copying object: #{e.message}" return false end
Copies an object from one Amazon Simple Storage Service (Amazon S3)
bucket to another.
Copies an object from one Amazon Simple Storage Service ( Amazon S3 ) bucket to another .
true if the object was copied; otherwise, false.
true if the object was copied ; otherwise false .
Boolean
s3_client
An initialized S3 client.
An initialized S3 client .
source_object_path
The path and file name of the object to copy.
The path and file name of the object to copy .
target_bucket_name
The name of the destination bucket.
The name of the destination bucket .
target_object_path
The path and file name of the copied object in the destination bucket.
The path and file name of the copied object in the destination bucket .
canned_acl
A predetermined ACL. Allowed values include 'private', 'public-read', 'public-read-write', 'authenticated-read', 'aws-exec-read', 'bucket-owner-read', and 'bucket-owner-full-control'. If not specified, the default is 'private'.
A predetermined ACL . Allowed values include ' private ' ' public - read ' ' public - read - write ' ' authenticated - read ' ' aws - exec - read ' ' bucket - owner - read ' and ' bucket - owner - full - control ' . If not specified the default is ' private ' .
storage_class
The S3 storage class for the copied object. Allowed values include 'STANDARD', 'REDUCED_REDUNDANCY', 'STANDARD_IA', 'ONEZONE_IA', 'INTELLIGENT_TIERING', 'GLACIER', and 'DEEP_ARCHIVE'. If not specified, the default is 'STANDARD'.
The S3 storage class for the copied object . Allowed values include ' STANDARD ' ' REDUCED_REDUNDANCY ' ' STANDARD_IA ' ' ONEZONE_IA ' ' INTELLIGENT_TIERING ' ' GLACIER ' and ' DEEP_ARCHIVE ' . If not specified the default is ' STANDARD ' .
example
exit 1 unless object_copied_with_additional_properties?( Aws::S3::Client.new(region: 'us-east-1'), 'doc-example-bucket/my-file.txt', 'doc-example-bucket1', 'copied-files/my-copied-file.txt', 'bucket-owner-read', 'STANDARD_IA' )
exit 1 unless object_copied_with_additional_properties? ( Aws :: S3 :: Client . new ( region : ' us - east - 1 ' ) ' doc - example - bucket / my - file . txt ' ' doc - example - bucket1 ' ' copied - files / my - copied - file . txt ' ' bucket - owner - read ' ' STANDARD_IA ' )