Skip to content

Instantly share code, notes, and snippets.

@hervenivon
Last active October 14, 2015 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hervenivon/75b05a71ca3f18d3d786 to your computer and use it in GitHub Desktop.
Save hervenivon/75b05a71ca3f18d3d786 to your computer and use it in GitHub Desktop.
Quickly generate presigned url for all files in a particular AWS S3 bucket location
{
"Region": "TOCHANGE",
"Bucket": "tochange",
"Location": "to/change/"
}
{
"AccessKeyId": "TOCHANGE",
"SecretAccessKey": "TOCHANGE"
}
#!/usr/bin/env ruby
require 'aws-sdk'
require 'json'
#loading credentials
creds = JSON.load(File.read('secrets.json'))
creds = Aws::Credentials.new(creds['AccessKeyId'], creds['SecretAccessKey'])
#loading config
conf = JSON.load(File.read('config.json'))
# Create a new S3 object
s3 = Aws::S3::Client.new(credentials: creds, region: conf['Region'])
# Create a resource object, simpler to use
resource = Aws::S3::Resource.new(client: s3)
bucket = resource.bucket(conf['Bucket'])
# enumerate every object in a bucket, and create a pre signed url with a 5 days expiration limit
bucket.objects(prefix: 'conf['Location']').each do |obj|
puts "#{obj.key} => #{obj.object.presigned_url(:get, expires_in: 5 * 24 * 60 * 60)}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment