Heroku is excellent for going from zero to product-market fit. You push code, it deploys. You add a database, it provisions. You scale, you move a slider. But somewhere around $1,000-$3,000/month in Heroku costs, the math stops working. The same workload on AWS costs 40-70% less. And AWS gives you capabilities that Heroku simply does not offer.
Here is how to migrate without breaking things.
Before you start: Is it actually time?
Do not migrate just because someone told you Heroku is not "real infrastructure." Migrate when one of these is true:
- Your Heroku bill exceeds $2,000/month and you need to reduce costs
- You need capabilities Heroku does not offer: VPC networking, custom instance types, managed Kubernetes, or regional deployment
- Enterprise customers require you to run on specific cloud providers for compliance reasons
- You need more control over your database (custom extensions, read replicas, specific versions)
If none of these apply, stay on Heroku. The engineering time you spend migrating is time you are not spending building features.
Step 1: Map your Heroku architecture (1-2 days)
Document everything Heroku is running for you: web dynos, worker dynos, database (Postgres), cache (Redis), add-ons, environment variables, scheduled jobs, and any custom buildpacks.
For each component, identify the AWS equivalent: EC2 or ECS for compute, RDS for PostgreSQL, ElastiCache for Redis, S3 for file storage, CloudWatch for logging, and so on.
Step 2: Set up the AWS foundation (1 week)
Use Terraform from day one. Do not click around in the AWS console. Everything should be infrastructure as code. This makes the migration reproducible and the resulting infrastructure maintainable.
Set up: VPC with public and private subnets, RDS PostgreSQL in the private subnet, ElastiCache Redis in the private subnet, an Application Load Balancer in the public subnet, ECS Fargate for your application containers (this is the closest thing to Heroku dynos), and a CI/CD pipeline using GitHub Actions.
If Terraform feels intimidating, tools like AWS Copilot or Pulumi provide a higher-level abstraction that is still infrastructure as code.
Step 3: Containerize your application (2-3 days)
Write a Dockerfile for your application. If you have been deploying on Heroku, your app is already 12-factor compliant, which means containerization is straightforward. The Dockerfile should install dependencies, build the app, and define the startup command.
Test the container locally. Run it with the same environment variables you use on Heroku. Make sure everything works before touching AWS.
Step 4: Migrate the database (1-2 days)
This is the riskiest step. Here is the approach that minimizes downtime:
- Take a snapshot of your Heroku Postgres database
- Download the snapshot using pg_dump
- Restore it to your RDS instance using pg_restore
- Set up logical replication from Heroku to RDS (if your Heroku plan supports it) to keep the databases in sync during the transition
- When you are ready to cut over, stop writes to Heroku, wait for replication to catch up, and switch your application to point at RDS
Total downtime with this approach: 5-15 minutes. Without replication, you can still do it with a maintenance window of 1-2 hours.
Step 5: DNS cutover (30 minutes)
Update your DNS to point to the AWS load balancer. Use a short TTL (60 seconds) in advance of the cutover so the change propagates quickly. Monitor your application closely for the first 24 hours after cutover.
Step 6: Decommission Heroku (1 week later)
Keep Heroku running for a week as a fallback. If something goes wrong on AWS, you can switch back by reverting the DNS change. Once you are confident everything is stable, shut down the Heroku app and cancel the add-ons.
Expected timeline and cost
Total migration time: 2-4 weeks with one engineer. If you bring in DevOps help, it can be done in 1-2 weeks. The engineering cost of the migration is typically $10,000-$25,000. The monthly savings are $1,000-$5,000, depending on your current Heroku spend. Break-even is usually 3-6 months.
Need help migrating from Heroku?
traztech has migrated dozens of startups from Heroku to AWS. We handle the entire process, from architecture design to DNS cutover, so you can keep building features.
Book a free strategy call