Skip to content

Instantly share code, notes, and snippets.

@blasterpal
Last active December 14, 2015 07:38
Show Gist options
  • Select an option

  • Save blasterpal/5051767 to your computer and use it in GitHub Desktop.

Select an option

Save blasterpal/5051767 to your computer and use it in GitHub Desktop.
upload file to s3
#use like
#AWS_KEY='asdasd' AWS_SECRET='123123' irb/script
source_file= 'nightly_s3_db.tar-ab'
target_subdir= 'ey-production-db-backups'
file_to_upload = File.basename(source_file)
bucket = 'co-devops'
key= "#{target_subdir}/#{file_to_upload}"
require 'fog'
storage = Fog::Storage.new({:provider => 'AWS', :aws_access_key_id => ENV['AWS_KEY'], :aws_secret_access_key => ENV['AWS_SECRET']})
dir = storage.directories.get(bucket)
# Put a file
# upload that resume
file = dir.files.create(
:key => "#{target_subdir}/#{file_to_upload]}",
:body => File.open("#{source_file}"),
:public => false
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment