Shrutee
Shrutee

Reputation: 1915

How to read yml file uploaded to aws s3

I have a yml file containing certain credentials and keys. So for extra security I wondered if it would be good to upload it to s3 and access using the private url or via aws object.

I tried giving the url in my development.rb to load the file which didn't work.

Next I tried creating an aws object and access the file in the s3 bucket.

s3  = AWS::S3.new(access_ key_id:  'xxx',  secret_access_key: 'yyy')

s3.buckets['my-bucket'].objects['file_name.yml']

I tried putting the url, file name without .yml to get access to the file and read it. But it keeps returning me empty {}. Does this have anything to do with url/file permission?? How can I achieve this?

This is the first time I am using aws and am not sure if my approach is correct or if this is the best way to keep sensitive data safe. Plz guide me on how to achieve this.

Thanks

Upvotes: 1

Views: 2283

Answers (1)

neo
neo

Reputation: 4116

I would use the following gem for this, much better than yaml implementation.

https://github.com/bkeepers/dotenv

install it and add to to you Gemfile.

then vim .env or create this new file using editor of your choice.

Add your keys:

S3_BUCKET=YOURS3BUCKET
SECRET_KEY=YOURSECRETKEYGOESHERE

and save it.

You can now call it from your application wherever you need the S3 keys.

ENV['S3_BUCKET']
ENV['SECRET_KEY']

Once its pushed to Heorku, just updated your environment variables, no need to push your secrets to Github.

Upvotes: 1

Related Questions