rubyopenstack-swiftaws-sdk-ruby

Copy blob from S3 to Swift using aws-sdk gem


I have a bunch of blobs stored in Amazon S3. Ruby aws-sdk gem seems to support Swift, we just need to pass endpoint:

swift_client = Aws::S3::Resource.new(
  endpoint: 'https://swift.me.com/,
  bucket: 'bucket',
  credentials: Aws::Credentials.new(access_key_id, secret_access_key))
swift_bucket = swift_client.bucket('bucket')

s3_client = Aws::S3::Resource.new(
  region: 'us-east-1',
  bucket: 'bucket',
  credentials: Aws::Credentials.new(access_key_id, secret_access_key))
s3_bucket = s3_client.bucket('s3-bucket')

# This object exists, s3_object.exists? => true
s3_object = s3_bucket.object('SOMEUID') 
swift_object = swift_bucket.object('SOMEUID') # UID is the same as in S3
# I want to copy s3 object to swift, so I do:
swift_object.copy_from(copy_source: "#{s3_bucket.name}/#{s3_object.key}")

At this point I get "Aws::S3::Errors::NoSuchKey: The specified key does not exist.". If I do the same thing vice versa (from Swift to S3), it works fine.

Is it even possible to copy data from S3 to Swift using aws-sdk gem or should I look for another tool?


Solution

  • The solution was in copying content manually, as Swift does not create object at copy_from execution.

    to_object.put(body: object.get.body)