Created
November 7, 2019 16:24
-
-
Save andersonfernandes/c4ba37c38d5efd8b6fdc7938d0a92c25 to your computer and use it in GitHub Desktop.
Script to download AWS S3 images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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