Skip to content

Instantly share code, notes, and snippets.

@sadikay
Created February 14, 2019 21:30
Show Gist options
  • Save sadikay/fd227133459f39e8cb714114de678cf6 to your computer and use it in GitHub Desktop.
Save sadikay/fd227133459f39e8cb714114de678cf6 to your computer and use it in GitHub Desktop.
A ruby script to move files from AWS S3 to Azure.
# gem install azure-storage --pre
# gem install aws-sdk
require 'aws-sdk'
require "azure"
require 'open-uri'
s3 = Aws::S3::Resource.new(
access_key_id: 'AKIA...',
secret_access_key: '************************************',
region: 'us-west-2',
endpoint: 'http://s3.amazonaws.com'
)
bucket = s3.bucket('myBucketName')
Azure.config.storage_account_name = "my-azure-cdn"
Azure.config.storage_access_key = "************************************"
azure_blob_service = Azure::Blob::BlobService.new
bucket.objects.each do |obj|
puts "=============================================="
begin
puts "https://s3.amazonaws.com/myBucketName/#{obj.key}"
content = ::File.open(open("https://s3.amazonaws.com/myBucketName/#{obj.key}"), 'rb') { |file| file.read }
blob = azure_blob_service.create_block_blob("azureBlockBlob", obj.key, content)
puts "DONE! => https://my-azure-cdn.blob.core.windows.net/azureBlockBlob/#{blob.name}"
rescue => e
puts "ERROR!!!! => #{e}"
end
puts "=============================================="
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment