Package of Ruby helpers for connecting Rails applications to AWS S3.
Add this line to your application's Gemfile
gem 'defra_ruby_aws'
And then update your dependencies by calling
bundle install
Add a new bucket with:
# config/initializers/defra_ruby_aws.rb
require "defra_ruby/aws"
DefraRuby::Aws.configure do |config|
config.buckets = [{
# bucket's name, required
name: "defra-ruby-aws",
# AWS bucket access credentials, required
credentials: {
access_key_id: "ACCESS_KEY_ID",
secret_access_key: "SECRET_ACCESS_KEY"
},
# optional - Default to "eu-west-1"
region: "eu-west-2",
# optional - Default to false. Will use AES256
encrypt_with_kms: true
}]
end
file_to_upload = Tempfile.new("test-upload-file.csv")
bucket = DefraRuby::Aws.get_bucket("defra-ruby-aws")
response = bucket.load(file_to_upload)
if response.successful?
# Do something
else
response.error # return the failure error
# Do something else
end
bucket = DefraRuby::Aws.get_bucket("defra-ruby-aws")
presigned_url = bucket.presigned_url("test-upload-file.csv")
bucket = DefraRuby::Aws.get_bucket("defra-ruby-aws")
response = bucket.delete("test-upload-file.csv")
if response.successful?
# Do something
else
response.error # return the failure error
# Do something else
end
If you have an idea you'd like to contribute please log an issue.
All contributions should be submitted via a pull request.
THIS INFORMATION IS LICENSED UNDER THE CONDITIONS OF THE OPEN GOVERNMENT LICENCE found at:
http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3
The following attribution statement MUST be cited in your products and applications when using this information.
Contains public sector information licensed under the Open Government license v3
The Open Government Licence (OGL) was developed by the Controller of Her Majesty's Stationery Office (HMSO) to enable information providers in the public sector to license the use and re-use of their information under a common open licence.
It is designed to encourage use and re-use of information freely and flexibly, with only a few conditions.