AWS Regrets: How to switch back to Heroku
As your company grows, it is natural to move from Heroku to AWS. What about the reverse?
Motivations: Deciding between ElasticBeanstalk and Heroku
Why I switched to AWS
Heroku’s cost structure is frustratingly nonlinear: once you hit certain limits, the cost skyrockets. On AWS, the cost scales much closer to linearly: if you want a little more functionality, you pay a little more.
I kept hitting these limits on Heroku, and saved over 90% switching to AWS ElasticBeanstalk. Plus, I got so much more fine-grained control: at first a blessing, but the complexity quickly became a curse.
Why I switched back to Heroku
I migrated my Django-based website rcvis.com from AWS ElasticBeanstalk to Heroku for three reasons:
- Test/Prod environment parity. Regardless of which Continuous Integration service you use, your test environment will be different from production. Among other disparities, AWS doesn’t provide any test platforms which validate your
.ebextensions
directory. - Simplicity. If you’re a small team, the complexity of AWS is probably not worth it. Trust me: I migrated from Heroku to AWS two years ago to save a few dollars, and the hours I spent in unnecessary DevOps makes me regret that decision.
- Stability. TravisCI recently stopped supporting free open-source users, despite claims on its website that it will “always” be free. Since this unsavory decision forced me to switch my CI service anyway, it made sense to choose a CI service which would also host my website on the same infrastructure.
This is a simple, two-line command on how to migrate your AWS RDS database to Heroku.
Step 1: Migrate the code, tests, and infrastructure
First, get your web app stood up on Heroku and get ready to swap your DNS to point to Heroku. Once its tested and working, you’re ready to migrate your database.
I recommend doing Steps 2 and 3 twice — once without taking down your ElasticBeanstalk database to make sure you understand the process and validate it works, then again but with your ElasticBeanstalk database in read-only mode so you make sure you don’t lose any data in the transition.
Step 2: Back up your ElasticBeanstalk database
Gather your credentials by going to your ElasticBeanstalk Configuration and scroll to the Database section and make note of the endpoint and username:
Back up your ElasticBeanstalk database by running:
pg_dump -h <eb-db-endpoint> -U <eb-db-username> -Fc -f dump.sql ebdb
You will then be prompted for your database password. If you’ve forgotten it, you can click “Edit” on the database configuration and change it.
If you’re backing up an AWS database not hosted on ElasticBeanstalk, change ebdb
to your RDS database name.
Step 3: Restore the database to Heroku
Collect credentials from Heroku. Click on your Postgres addon:
Then click Settings > Database Credentials and take note of your credentials:
Use that information to restore dump.sql
to Heroku:
pg_restore -h <heroku-db-endpoint> -c -d <heroku-db-name> -U <heroku-db-user> dump.sql
Summary
Use pg_dump
to dump the ElasticBeanstalk database to a local file, then pg_restore
to restore it. Make sure you use -Fc
on pg_dump
to make the file ingestible by pg_restore
.
For more help on how to migrate a Django Web App from AWS ElasticBeanstalk to Heroku, see how I did it in these two Pull Requests on Github: [1] Initial migration, [2] Static Files deployment.
You can view RCVIS’ Ranked Choice Voting Visualizations now live on Heroku at rcvis.com.