Problems getting s3 in the Rails 3 Refinery CMS App

I am trying to get a cms image store for treatment facilities on Amazon s3 and I am following this guide:

http://refinerycms.com/guides/how-to-use-amazon-s3-for-storage

But I am locked here:

There are several ways to set with your permissions, including unix variables or manually setting them through Ruby using ENV.

How to determine these credentials. I put something like: S3_KEY => "my_key" in the environment.rb file? I tried this and it did not work. I also tried this:

AWS::S3::Base.establish_connection!( :access_key_id => ENV['S3_KEY'] || 'key_goes_here', :secret_access_key => ENV['S3_SECRET'] || 's3_secret_key_here', ) 

I can’t figure out how to do this. Any ideas are welcome.

+4
source share
1 answer

The safest way is to specify them as environment variables, so they are not included in your source code. If you are the only one who has access to the source, then specifying them as you describe should work.

You can specify them in your ~/.bashrc

 export S3_KEY=mykey export S3_SECRET=mysecret 

Or, if you are just testing locally, you can add them to the rails command.

 $ S3_KEY=mykey S3_SECRET=mysecret rails server 

If you do not want / cannot use environment variables, another method is to use an initializer to load credentials from the yml file : config/initializers/s3_credentials.rb

 # Load AWS::S3 configuration values # S3_CREDENTIALS = \ YAML.load_file(File.join(Rails.root, 'config/s3_credentials.yml'))[Rails.env] # Set the AWS::S3 configuration # AWS::S3::Base.establish_connection! S3_CREDENTIALS['connection'] 

config/s3_credentials.yml

 development: &defaults connection: :access_key_id: AAAAAA_your-key-here :secret_access_key: 4rpsi235js_your-secret-here :use_ssl: true bucket: project-development acl: public-read production: <<: *defaults bucket: project 
+6
source

Source: https://habr.com/ru/post/1347471/


All Articles