This tutorial will show you how to create and connect a postgres database hosted with Amazon Web Service’s RDS to a Heroku application.
- Create and launch a database instance on RDS with the default settings. Make sure ‘Public accessibility’ is set to Yes.
- Once your instance is created, click on it to view the details and settings.
- Scroll half way down the page to see your security group. Click on the security group so you can make edits.
- On the security group page, click the Inbound tab at the bottom of the page. Click edit, then change the Source to 0.0.0.0/0. Your security group should look like this:
- Go back to RDS and click ‘Parameter groups’ on the left hand menu
- Click Create parameter group
- Give it a name like ‘forcessl’ and click Create. Then click on the newly created parameter group, filter to rds.force_ssl. Click edit parameter and change the value to 1. This setting will force all connections to your database to use SSL.
- Click on your database instance again. Click the Instance Actions at the top left, then click Modify. Scroll towards the bottom and change the parameter group to your newly created group called forcessl. Click next, then change the radio option to Apply immediately, and click Modify DB instance.
- Download the SSL certificate from AWS using this link: https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem
- Place it in the root of your application directory
- Set your DATABASE_URL to the following format:
Note: when I say instance_endpoint, I mean the RDS endpoint that can be found under your instance details, ending with us-east-1.rds.amazonaws.com.
You can now connect to your database securely using SSL. Test it out with psql by running:
psql -h instance_endpoint -p 5432 “dbname=mydbname user=dbuser sslrootcert=\Users\casey\SSH\rds-ca-2015-root.pem sslmode=verify-full”
You will see at the top that are you connected using SSL.
You can also connect using DataGrip by selecting the SSL tab on your connection and providing the path to the SSL certificate like so: