Elastic Beanstalk has built in support for RDS. But, I want to use Postgresql with Elastic Beanstalk. Which will be the best approach for doing this?
2 Answers
The easiest and cleanest way I found, assuming you're using Elastic Beanstalk CLI eb:
Create an instance (follow the steps):
eb initThis will create an instance with MySQL.
Once it's created, stop it.
eb stopThis will stop your instance and delete the MySQL database that was created by the initial setup.
Edit your instance configuration file in
.elasticbeanstalkdirectory at the root of your project, replace DBEngine entry in the[aws:rds:dbinstance]section by postgres.vi .elasticbeanstalk/optionsettings.<my-app>-env [aws:rds:dbinstance] DBDeletionPolicy=Delete DBEngine=postgres DBInstanceClass=db.t1.micro DBSnapshotIdentifier= DBUser=<dbrootuser>Restart the instance:
eb start Starting application ".<my-app>". Waiting for environment "<my-app>-env" to launch. 2014-07-17 17:53:15 INFO createEnvironment is starting. 2014-07-17 17:53:21 INFO Using elasticbeanstalk-us-east-1-xxxxxxx as Amazon S3 storage bucket for environment data. 2014-07-17 17:53:52 INFO Created EIP: nn.nnn.nnn.nnn 2014-07-17 17:53:58 INFO Created security group named: awseb-e-xxx 2014-07-17 17:54:10 INFO Creating RDS database named: <db name>. This may take a few minutes. 2014-07-17 18:06:09 INFO Created RDS database named: <db name> 2014-07-17 18:07:07 INFO Waiting for EC2 instances to launch. This may take a few minutes.Check the status. Once it gets green, you'll now have a postgres database.
eb status --verbose URL : <my-app>-env-xxxxx.elasticbeanstalk.com Status : Ready Health : Green RDS Database: YYYYDatabase | <db name>.zzzzzz.us-east-1.rds.amazonaws.com:5432 Database Engine: postgres 9.3.3 Allocated Storage: 10 Instance Class: db.t1.micro Multi AZ: False Master Username: <dbrootuser> Creation Time: 2014-07-17 18:02:28 DB Instance Status: available
- 151
You can set your custom postgres database running anywhere and make your rails application to use it from your database.yml file settings.
For e.g.
You can get a hosted postgres instance on Heroku Postgres - it gives very nicely formatted configuration details for ActiveRecord. You just have to get them in your database.yml file.