Setting up Amazon RDS for Heroku / Rails
Amazon has a mysql service. It scales up to 68gb ram and deals with backups for you. Heroku lets you use this. This means that rather than paying for the Ronin DB plan, you can just make your own db with RDS on aws and only pay for dynos from heroku. Plus, if you’re tied to mysql, you don’t have to spend tons of time dealing with postgres.
This is all pretty awesome.
Env
First, d/l the RDS cli here.
Then set some stuff. You might want to put this in your ~/.profile
1 2 3 4 5 6 |
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home export AWS_RDS_HOME=~/Projects/RDS/ export PATH=$PATH:$AWS_RDS_HOME/bin cd $AWS_RDS_HOME |
Then fill in the “credential-file-path.template” with your security credentials that you can get from hovering over “Your account” on the aws homepage.
Then:
1 2 3 4 |
export AWS_CREDENTIAL_FILE=~/Projects/RDS/credential-file-path.template chmod 600 credential-file-path.template |
If it worked, then you’ll be able to enter rds --help.
Create the instance
Here are your options:
db.m1.small (1.7 GB of RAM, $0.11 per hour). db.m1.large (7.5 GB of RAM, $0.44 per hour) db.m1.xlarge (15 GB of RAM, $0.88 per hour). db.m2.2xlarge (34 GB of RAM, $1.55 per hour). db.m2.4xlarge (68 GB of RAM, $3.10 per hour).
To make one, use:
rds-create-db-instance --db-instance-identifier [name]\
--allocated-storage 5 \
--db-instance-class db.m1.small \
--engine MySQL5.1 \
--master-username [user] \
--master-user-password [pw] \
--db-name [name] \
--headers
The allocated-storage option is basically the number of gigs that your db will take up, not including backups.
For detailed info on all the options, checkout the api docs
Assuming that worked, you can check on what’s happening with this command:
rds-describe-db-instances --headers
Once it provisions the instance, just add the RDS add-on to heroku in your app account and authorize heroku as explained here..
Then it’s just:
1 2 3 4 5 |
heroku rake db:create heroku rake db:schema:load heroku restart |
For more detailed info on migrating databases, see heroku’s guide here.
It’s all so beautifully easy and fast.
November 22, 2009

