Skip to content

Instantly share code, notes, and snippets.

@pgib
Created December 14, 2018 21:14
Show Gist options
  • Save pgib/a1130d819f7bba48dbc40c426507d141 to your computer and use it in GitHub Desktop.
Save pgib/a1130d819f7bba48dbc40c426507d141 to your computer and use it in GitHub Desktop.
Sign an S3 URL
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem 'aws-sdk'
#!/usr/bin/env ruby
# vim ft=ruby
require 'bundler'
Bundler.setup
require 'aws-sdk'
client = Aws::S3::Client.new(region: 'us-west-2')
object = Aws::S3::Object.new(client: client, bucket_name: ENV['bucket'], key: ARGV[0])
if object.size > 0
puts object.presigned_url(:get, expires_in: 604800)
else
puts "#{ARVG[0]} not found."
exit 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment