ruby/example_code/s3/copy_object_between_buckets.rb
def run_me
  source_bucket_name = 'doc-example-bucket1'
  source_key = 'my-source-file.txt'
  target_bucket_name = 'doc-example-bucket2'
  target_key = 'my-target-file.txt'
  region = 'us-west-2'

  s3_client = Aws::S3::Client.new(region: region)

  puts "Copying object '#{source_key}' from bucket '#{source_bucket_name}' " \
    "to bucket '#{target_bucket_name}'..."

  if object_copied?(
    s3_client,
    source_bucket_name,
    source_key,
    target_bucket_name,
    target_key)
    puts 'The object was copied.'
  else
    puts 'The object was not copied. Stopping program.'
    exit 1
  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
  source_bucket_name = 'doc-example-bucket1'
  source_key = 'my-source-file.txt'
  target_bucket_name = 'doc-example-bucket2'
  target_key = 'my-target-file.txt'
  region = 'us-west-2'
  s3_client = Aws::S3::Client.new(region: region)
  puts "Copying object '#{source_key}' from bucket '#{source_bucket_name}' " \
    "to bucket '#{target_bucket_name}'..."
  if object_copied?(
    s3_client,
    source_bucket_name,
    source_key,
    target_bucket_name,
    target_key)
    puts 'The object was copied.'
  else
    puts 'The object was not copied. Stopping program.'
    exit 1
  end
end
def run_me source_bucket_name = 'doc-example-bucket1' source_key = 'my-source-file.txt' target_bucket_name = 'doc-example-bucket2' target_key = 'my-target-file.txt' region = 'us-west-2' s3_client = Aws :: S3 :: Client . new ( region : region ) puts "Copying object '#{source_key}' from bucket '#{source_bucket_name}' " "to bucket '#{target_bucket_name}'..." if object_copied? ( s3_client , source_bucket_name , source_key , target_bucket_name , target_key ) puts 'The object was copied.' else puts 'The object was not copied. Stopping program.' exit 1 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 .