Skip to content

Instantly share code, notes, and snippets.

@andersonfernandes
Created November 7, 2019 16:24
Show Gist options
  • Save andersonfernandes/c4ba37c38d5efd8b6fdc7938d0a92c25 to your computer and use it in GitHub Desktop.
Save andersonfernandes/c4ba37c38d5efd8b6fdc7938d0a92c25 to your computer and use it in GitHub Desktop.
Script to download AWS S3 images
require 'aws-sdk'
credentials = Aws::Credentials.new(ENV['S3_ACCESS_KEY'], ENV['S3_SECRET_ACCESS_KEY'])
Aws.config.update(
region: 'sa-east-1',
credentials: credentials
)
objects_keys = []
objects_keys.each_with_index do |key, index|
print "#{index}.. "
s3_client = Aws::S3::Client.new
File.open("/tmp/images/#{key}.jpg", 'wb') do |file|
s3_client.get_object(bucket: 'stant', key: "store/#{key}") do |data|
file.write(data)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment