Guides / Migrate a Django app from Heroku to your own AWS account with Django Cloud
Migrate a Django app from Heroku to your own AWS account with Django Cloud
Moving a Django app off Heroku is mostly three jobs: copy the database, move the settings, and switch the domain. Done in the right order, the site is down for a few minutes at most. This guide shows the order.
Before you start
- Pick the AWS region. For European users, choose a European region.
- Make a list of your Heroku add-ons (Postgres, Redis, email, scheduler). Each needs a replacement.
- Check your project runs outside Heroku:
gunicornin the requirements,ALLOWED_HOSTSand static files configured.
Step 1: export your settings
heroku config --shell -a your-app > heroku.env
Remove Heroku-specific entries (such as DATABASE_URL, which will change) before you reuse the file. Keep the file private and delete it afterwards.
Step 2: deploy the app to the new place, with an empty database
Deploy first and check that the app starts. It is much easier to fix a startup error now than during the final switch.
Step 3: copy the database
heroku maintenance:on -a your-app
heroku pg:backups:capture -a your-app
heroku pg:backups:download -a your-app # writes latest.dump
Then restore the dump into the new database:
pg_restore --verbose --clean --no-acl --no-owner -d "$NEW_DATABASE_URL" latest.dump
Enabling maintenance mode first stops new writes, so the copy is complete. For a large database, do a test run earlier to learn how long the copy takes.
Step 4: check before you switch
- Log in, open a few pages and make one harmless edit.
- Compare row counts of two or three important tables with the old database.
- Check that emails, file uploads and background jobs work.
Step 5: switch the domain
Lower the DNS TTL a day before, so the change spreads fast. Point the domain at the new app, wait until the certificate is issued, then leave Heroku in maintenance mode for a day as a safety net before you delete it.
Common surprises
- Add-ons you forgot: schedulers, Redis, log drains.
- Uploaded files: Heroku disks are temporary. If your app stored uploads on disk, they are already gone; use object storage.
- The old database URL: make sure nothing, including a cron job, still points at it.
Or skip it
Django Cloud takes your requirements.txt, pyproject.toml or uv.lock as they are, connects a Postgres database to your app, runs migrations before each release and sets up your own domain with a certificate. Deploying is one command.
pip install djangocloud-cli
djangocloud deploy
Free plans are available for students, AWS Activate startups, open-source, non-profit and research projects. See how Django Cloud compares with other ways to host Django.
Django is a registered trademark of the Django Software Foundation. Django Cloud is not affiliated with or endorsed by it. Found a mistake in this guide? Tell us and we will fix it.