0
votes

If I wanted to have my development and production app access different buckets with a different key id and secret, is such possible? Or would I need to create another AWS account?

I looked around but couldn't find anything useful. Ideally, it would be good if I could have multiple buckets in one AWS account and have different key ids and secrets for those bucket access.

2

2 Answers

1
votes

As far as getting the credentials into your app, then you can either thane separate YAML files you copy onto the servers or (on heroku) use environment variables, as John said.

You don't however need multiple AWS accounts. You can use iam to create extra users inside your account, with their own access key/secret key and then grant them appropriate permissions. You can for example create an account that can only access an S3 bucket but can't do anything else. If you're going to save keys on your instances I highly recommend going this route rather than using the 'master' access key for your account (which allows unfettered access to your AWS account)

You can either create/configure these users via the IAM api, or you can use the GUI at the amazon console

0
votes

In your config directory create a file called s3.yml, Inside put:

development:
  bucket: development_bucket_name
  access_key_id: development_amazon_key
  secret_access_key: development_secret_key

create a similar file (s3.yml) for production.

production:
  bucket: production_bucket_name
  access_key_id: production_amazon_key
  secret_access_key: production_secret_key

Do not check the file into source control. Instead place the production one on the server in the config directory for development just leave it in config locally.

In environment/development.rb and production.rb

S3_CONFIG = YAML.load_file Rails.root.join("config/s3.yml")

Wherever you are explicitly are calling bucket_name, amazon_key, secret_key instead use

S3_CONFIG[Rails.env]["bucket"], etc