Point Heroku application to AWS RDS database

前端 未结 3 1714
深忆病人
深忆病人 2020-12-29 12:41

I need to point my Heroku application to my AWS RDS database. My RDS database is up and running and has a security group with 0.0.0.0/0 access.

Currently, I\'ve rem

3条回答
  •  醉话见心
    2020-12-29 12:57

    I figured out how to point heroku app to AWS RDS database. This allows me to have a giant database, test out Amazon's free tier for a year and have more customization over my database instance. This answer is in response to @pseudopeach question (pardon the delay).

    So this is a pretty simple set up. To configure RDS for Heroky you need to know heroku well and you need to know AWS VERY well.

    1. AWS side

    a) set up your region. Pick the region closest to you e.g. US EAST (Ohio)

    b) then click services tab and select rds

    c) i have a db ts micro (i think that's the free tier option)

    d) do the rds set up and after it is up and running you click "instance actions" and see details

    e) here you will be able to view your db-username, dbname, endpoint (which for me is a url similar to this [dbname].[randomstring].us-east-1.rds.amazon.com) and port number. You need these things plus you db password for the heroku side.

    1. Heroku side

    a) go to your heroku app on heroku.com, then settings b) click revealconfig variables

    typical heroku variables look like this:

    DATABASE_URL xxxxxx

    HEROKU_POSTGRESQL_VIOLET_URL xxxxxx

    LANG xxxxxx

    RACK_ENV production

    RAILS_ENV production

    SECRET_KEY_BASE xxxxxx

    you need to do change these up pretty drastically

    DATABASE_URL [note: this changes to a different and long url – mine looks like this broken down for easy understanding]

    postgres://

    [db-username]:

    [your db password]

    @[endpoint]:

    [your db port number]/

    [db name]

    ?sslca=config/amazon-rds-ca-cert.pem

    &sslmode=require

    &encrypt=true

    example database url:
    postgres://jdoe:supersecretpassword@mydb.coua7574xvna.us-east-1.rds.amazonaws.com:5432/mydb?sslca=config/amazon-rds-ca-cert.pem&sslmode=require&encrypt=true

    EXTERNAL_DATABASE amazon-rds-ca-cert.pem

    EXTERNAL_DATABASE_CA amazon-rds-ca-cert.pem

    LANG (same)

    RACK_ENV (same)

    RAILS_ENV (same)

    RDS_DB_PASS [your db password]

    RDS_DB_PORT [your db port number i.e. 5432]

    RDS_READS_DB_NAME [db name]

    RDS_HOST [end point url]

    RDS_USER [db-username]

    This worked for me and I got a free year of RDS for a database way over 10,000 rows (which I believe is the free tier limit on heroku). I used postgreSQL as my database, so these configs might be biased toward postgres.

提交回复
热议问题