Method: AWS::Rails.load_yaml_config

Defined in:
lib/aws/rails.rb

.load_yaml_config ⇒ Object

Loads AWS configuration options from RAILS_ROOT/config/aws.yml.

This configuration file is optional. You can omit this file and instead use ruby to configure AWS inside a configuration initialization script (e.g. RAILS_ROOT/config/intializers/aws.rb).

If you have a yaml configuration file it should be formatted like the standard database.yml file in a Rails application. This means there should be one section for Rails environment:

development:
access_key_id: YOUR_ACCESS_KEY_ID
secret_access_key: YOUR_SECRET_ACCESS_KEY
simple_db_consistent_reads: false

production:
access_key_id: YOUR_ACCESS_KEY_ID
secret_access_key: YOUR_SECRET_ACCESS_KEY
simple_db_consistent_reads: true

You should also consider DRYing up your configuration file using YAML references:

development:
access_key_id: YOUR_ACCESS_KEY_ID
secret_access_key: YOUR_SECRET_ACCESS_KEY
simple_db_consistent_reads: false

production:
<<: *development
simple_db_consistent_reads: true

The yaml file will also be ERB parsed so you can use ruby inside of it:

development:
access_key_id: YOUR_ACCESS_KEY_ID
secret_access_key: <%= read_secret_from_a_secure_location %>
simple_db_consistent_reads: false

production:
<<: *development
simple_db_consistent_reads: true


103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/aws/rails.rb', line 103

def self.load_yaml_config
  
  path = Pathname.new("#{rails_root}/config/aws.yml")
  
  if File.exists?(path)
    cfg = YAML::load(ERB.new(File.read(path)).result)
    unless cfg[rails_env]
      raise "config/aws.yml is missing a section for `#{rails_env}`"
    end
    AWS.config(cfg[rails_env])
  end
  
end