Migrate from Self-Hosting to Cloud

In this guide, you'll learn how to move a self-hosted Medusa application to Cloud, including its code, database, files, and domains. The steps apply to any hosting setup, such as a virtual machine, a container platform, or a platform-as-a-service provider.

Migration Overview#

When you self-host, you manage the server, database, Redis, file storage, and deployment pipeline. On Cloud, Medusa provisions and manages all of them per environment, so a migration comes down to moving your code, data, and traffic:

Self-Hosted Component

On Cloud

What Changes for You

Server and worker instances

Created and scaled automatically.

You no longer need deployment scripts and a pipeline.

PostgreSQL database

A managed database per environment.

You import a dump of your existing database.

Redis

A managed Redis server per environment.

You remove the Redis modules from your configuration. There's no Redis data to migrate.

File storage

Managed S3 storage per environment.

You choose how to handle your existing files.

Email provider

Medusa Emails, or your existing provider.

You can keep your Notification Module Provider or switch to Medusa Emails.

Storefront

Hosted on Cloud alongside your Medusa application.

You deploy the storefront in the same project, then point your domain to it.

This guide assumes you deploy your storefront to Cloud along with your Medusa application.

Your Cloud project isn't live until you point your domain to it, so you can prepare and test everything on Cloud while your self-hosted application keeps serving traffic.


Step 1: Create a Cloud Organization#

An organization holds your Cloud projects, team members, and billing details. If you don't have one, sign up for Cloud to create it.


Step 2: Prepare Your Medusa Application#

Cloud deploys from a GitHub repository. If your code is in another Git provider or only on your server, push it to a GitHub repository first.

To deploy your storefront with your Medusa application, both must be in the same repository as a monorepo. If they're in separate repositories, the Prerequisites guide explains how to set up the monorepo.

Note: Cloud requires Medusa v2.7.0 or later to configure the managed Redis and S3 resources. If your application uses an earlier version, update it first or contact support.

Cloud also configures production infrastructure automatically, which can conflict with your self-hosted infrastructure configurations. Remove the following before you deploy.

Remove Infrastructure Modules#

Cloud registers the Redis and S3 modules for you. Remove any of the following from the modules array in medusa-config.ts:

Remove these modules entirely instead of registering them conditionally, such as only when REDIS_URL is set. A conditional registration can still conflict with Cloud's modules and fail the deployment.

Remove Database and Redis Connection Options#

Cloud manages the database connection, SSL configuration, connection pooling, and Redis. Remove the databaseUrl, databaseDriverOptions, and redisUrl options from projectConfig in medusa-config.ts, since keeping them may cause deployment or migration failures. For example:

medusa-config.ts
module.exports = defineConfig({
  projectConfig: {
    // remove databaseUrl, databaseDriverOptions,
    // and redisUrl
    http: {
      storeCors: process.env.STORE_CORS!,
      adminCors: process.env.ADMIN_CORS!,
      authCors: process.env.AUTH_CORS!,
      jwtSecret: process.env.JWT_SECRET,
      cookieSecret: process.env.COOKIE_SECRET,
    },
  },
  // remove the Redis and S3 modules from `modules`
})

Remove Migrations from Your Scripts#

Cloud runs database migrations on every deployment. In your package.json:

  • Remove medusa db:migrate from your start script.
  • Remove the predeploy script if it only runs migrations.
  • Keep a build script that runs medusa build, since Cloud uses it to build your application.

Cloud ignores host-specific deployment files, such as a Dockerfile or a process manager configuration, so you can remove them whenever you're ready after the migration.

Check the Remaining Prerequisites#

Refer to the Prerequisites for New Projects guide for the supported Node.js versions, the monorepo setup for deployments with storefronts, and more. Then, commit and push the changes to your GitHub repository.

Tip: After these changes, the branch may no longer run on your self-hosted setup. If your self-hosted pipeline deploys from the same repository, make the changes in a separate branch. You can choose the branch the Production environment deploys from when you create the project.

Step 3: Collect Your Environment Variables#

Your Cloud project needs most of your self-hosted application's environment variables. Export them into a .env file, leaving out the ones Cloud manages or reserves, and add it when you create the project in the next step.

Leave out these variables, which Cloud sets for you:

  • DATABASE_URL and REDIS_URL
  • NODE_ENV, PORT, and MEDUSA_WORKER_MODE
  • The connection variables of the Redis and S3 modules that you removed, such as S3_BUCKET or CACHE_REDIS_URL

Find the full list of reserved names in the Environment Variables guide.

Keep these variables:

  • JWT_SECRET and COOKIE_SECRET. If you use the same values as your self-hosted application, existing customer and admin sessions remain valid after the switch.
  • The variables of your third-party integrations, such as payment, fulfillment, tax, and ERP credentials.
  • Any variables your customizations read.

Cloud configures Cross-Origin Resource Sharing (CORS) between your storefront and Medusa application. You only need STORE_CORS, ADMIN_CORS, and AUTH_CORS if other clients, such as a mobile app, send requests to your Medusa application.

Storefront Environment Variables#

Collect your storefront's environment variables in a separate .env file. Cloud injects the backend URL, publishable API key, and storefront URL, so leave those out and keep the rest, such as analytics or payment provider keys.


Step 4: Create the Cloud Project#

Requires one of the roles:AdminDeveloper

Create a Cloud project from your GitHub repository by following the Create Project from an Existing Application guide. Pay extra attention to these settings:

  • Region: Choose the region closest to your customers. You can't change it later.
  • Project root directory and Storefront root directory: Set these to the paths of your Medusa application and storefront in the monorepo.
  • Environment variables: Paste or import the backend and storefront .env files from the previous step.

Medusa then provisions the project's resources and deploys your Medusa application and storefront to the Production environment, with an empty database that you fill in the next step.

If the deployment fails, refer to the Troubleshooting guide. After moving from self-hosting, the cause is often a leftover Redis or database configuration.


Step 5: Migrate the Database#

Your database holds your products, orders, customers, users, API keys, and settings. To move it, create a dump of the self-hosted database and import it into the Cloud environment's database.

Note: Cloud uses PostgreSQL v16, so the dump must come from a PostgreSQL v16 database with a matching pg_dump version. If your self-hosted database uses an earlier version, upgrade it first, or restore it into a local PostgreSQL v16 database and create the dump from there. If it uses a newer version, such as v17 or v18, follow the steps in Migrate from a Newer PostgreSQL Version.

Create the Dump#

Run pg_dump with the custom format against your self-hosted database. The machine you run it on must reach the database, so if it only accepts private connections, run the command from your server:

Terminal
pg_dump -Fc \
  -d postgres://user:password@host:5432/medusa \
  -f medusa.dump

Replace the connection string with your database's connection string.

Migrate from a Newer PostgreSQL Version#

Some hosting providers create databases with PostgreSQL v17 or later. A dump created from these versions doesn't work with Cloud's PostgreSQL v16, and a v16 pg_dump refuses to dump a database that runs a newer version.

Instead, you can move the data through a local PostgreSQL v16 database:

  1. Create a plain SQL dump of your self-hosted database. Use a pg_dump version that matches your database's version:
Terminal
pg_dump --no-owner --no-privileges \
  -d postgres://user:password@host:5432/medusa \
  -f medusa.sql
  1. Start a local PostgreSQL v16 database. For example, using Docker:
Terminal
docker run -d --name medusa-pg16 \
  -e POSTGRES_PASSWORD=postgres \
  -p 5433:5432 postgres:16
  1. Restore the plain SQL dump into the local database with psql:
Terminal
psql postgres://postgres:postgres@localhost:5433/postgres \
  -f medusa.sql
  1. Create the custom-format dump from the local database with a v16 pg_dump. For example, using the pg_dump in the Docker container:
Terminal
docker exec medusa-pg16 pg_dump -Fc -U postgres \
  -d postgres -f /tmp/medusa.dump
docker cp medusa-pg16:/tmp/medusa.dump ./medusa.dump

You can then import medusa.dump as explained in the next section.

Note: The plain SQL dump can contain settings that PostgreSQL v16 doesn't support, such as SET transaction_timeout. psql logs an error for these lines and continues the restore, so you can ignore them. Check the output for other errors, which can mean that your database uses features unavailable in v16.

Import the Dump#

Requires one of the roles:AdminDeveloper

To import the dump into your Cloud environment:

  1. Open the Production environment's dashboard, then click Database in the sidebar.
  2. In the Database dump section, upload the dump file to import it.
  3. After the import completes, redeploy the environment's live deployment.

Learn more in the Database guide.

Warning: The import replaces the environment's database with the dump's data. It also drops and recreates the tables, so requests can fail until you redeploy.

The redeployment also runs pending migrations, so if your Cloud deployment uses a newer Medusa version, Medusa updates the imported schema.

Rehearse, Then Run the Final Import#

Your self-hosted application keeps receiving orders after you create a dump, so the first import is outdated by the time you go live. Import the database twice:

  1. Rehearsal: Import a dump now and test the deployment to confirm the import works and see how long it takes.
  2. Final import: During the switch in Step 9, you stop writes to the self-hosted application, create a new dump, and import it again.

Step 6: Migrate Files#

The database stores the URLs of uploaded files, such as product images. After the import, these URLs still point to your previous storage, while new uploads go to Cloud's managed S3 storage. You can't copy files into Cloud's bucket directly, so choose one of these approaches:

Approach

When It Fits

How It Works

Move the files with a migration script

Your files are on the server's disk, or you plan to shut down the previous storage.

You add a migration script that uploads the files to Cloud's storage and updates the records that reference them. Your AI agent can write the script for you.

Keep the previous storage for existing files

Your files are in an S3-compatible bucket or another external storage service.

You keep the bucket and its files publicly readable. Existing URLs keep working, and new uploads go to Cloud's storage.

Keep using your own bucket

You prefer to have all files, existing and new, in a bucket that you manage.

You keep the S3 File Module Provider in medusa-config.ts and add its variables to Cloud. Learn more in the S3 guide.

Move Files with a Migration Script#

A data migration script lives in your application's src/migration-scripts directory. Cloud runs it once per environment during a deployment, which fits a one-time task like moving files.

An AI agent, such as Claude Code or Codex, can write the script for you. Connect it to the Docs MCP server first so the script follows Medusa's conventions, then give it a prompt like the following:

Example Prompt
Write a Medusa data migration script in
src/migration-scripts that moves this project's files to
the configured File Module Provider. The script must:

1. Find the records that store file URLs, such as product
   images and thumbnails, and the custom data models that
   reference files.
2. Skip the URLs that it already moved, so it's safe to
   run again.
3. Download each file from its current URL, and upload it
   with the uploadFilesWorkflow.
4. Update each record with the new file URL.
5. Process the records in batches, and log its progress.

When you deploy the commit that adds the script, Cloud runs it and uploads the files to the environment's managed storage. The script reads file URLs from the database, so deploy it after you import the database.

The final import replaces the database, including the updated file URLs and the record that the script ran. So, the script runs again in the next deployment and moves any files still at their previous URLs.

Tip: The script downloads the files from their current URLs, so your previous storage must stay reachable until the script finishes.
Warning: With the Local File Module Provider, your files are on the self-hosted server's disk and their URLs use its address. They become unavailable once you shut the server down, so move them with a migration script before then.

If your storefront restricts which hosts it loads images from, such as with remotePatterns in Next.js, add the Cloud bucket's host from the environment's S3 details.


Step 7: Test the Cloud Deployment#

Before you switch traffic, verify that the Cloud deployment works with your imported data. Use the environment's default URLs, the medusajs.app URL for the backend and the medusajs.site URL for the storefront, both in the environment's dashboard. Check the areas a migration typically affects:

  • Log in to the Medusa Admin with an existing admin user, and confirm that products, orders, and customers appear.
  • Open the storefront, and confirm that it shows your products and their images.
  • Place a test order in the storefront with your payment provider's test mode, if possible.
  • Trigger an email, such as a password reset, and confirm you receive it.
  • Check the logs for errors from subscribers, scheduled jobs, and third-party integrations.

Update Third-Party Integrations#

Some third-party services depend on your backend's address and may need an update before you go live:

  • Webhooks: Update webhook URLs, such as a payment provider's, to the Cloud backend's URL. If you keep the same domain with a backend custom domain, the URL stays the same.
  • IP allowlists: If a service or firewall only accepts requests from specific IP addresses, add Cloud's outgoing IP addresses to its allowlist.
  • Emails: If you removed your email Notification Module Provider, Cloud sends emails with Medusa Emails. To send from your domain, add a sender domain. If you keep your provider, emails continue to go through it.

Step 8 (Optional): Set Up Custom Domains#

Requires one of the roles:AdminDeveloper

By default, Cloud serves your storefront from a medusajs.site subdomain and your backend from a medusajs.app subdomain. To keep your own domain, such as shop.acme.com, add it as a custom domain on Cloud.

Note: Storefront custom domains require the Launch plan or higher, and backend custom domains require the Scale plan or higher. Learn how to change your plan.

To add your storefront's domain:

  1. In the Production environment's dashboard, click Domains in the sidebar.
  2. Under the Custom storefront domains section, click Add domain.
  3. Enter your domain name and click Continue.

Cloud then shows the DNS records to add at your domain provider. These records send your domain's traffic to Cloud, so if the domain currently serves your self-hosted store, wait to add them until the switch in the next step.

Follow the same steps for your backend's domain under the Custom backend domains section. The Custom Domains guide covers both in more detail.

Tip: Lower the TTL of your domain's existing DNS records a day before the switch so DNS changes take effect faster, shortening the maintenance window.

If you skip this step, your store stays available at its medusajs.site and medusajs.app URLs, and you can add a custom domain later.


Step 9: Switch Traffic to Cloud#

Once you're happy with the Cloud deployment, switch your live traffic to it. You pause writes to the self-hosted application while moving the final data, so switch during a low-traffic period:

  1. Stop writes to the self-hosted application. Put your self-hosted storefront in maintenance mode or stop the self-hosted server, so customers don't place orders that the final dump would miss.
  2. Let background work finish. Since there's no Redis data to migrate, give in-progress workflows and queued events time to complete before you stop the server.
  3. Run the final import. Create a new dump and import it, then redeploy the environment.
  4. Point your domains to Cloud. If you set up custom domains, add their DNS records at your domain provider. Otherwise, redirect your previous domain to the storefront's medusajs.site URL.
  5. Verify the live store. Once the domain shows as verified, place an order in the storefront and confirm it appears in the Medusa Admin on Cloud.

Cloud connects the storefront to your Medusa application, so you don't change the storefront's backend URL. The exception is a backend custom domain: after its DNS changes take effect, update the backend URL in the storefront's environment variables.


Step 10: Clean Up After the Migration#

Keep your self-hosted setup available, but stopped, for a few days after the switch, so you can point your domains back to it if needed. Orders placed on Cloud in the meantime don't exist in the self-hosted database.

Once you're confident in the Cloud deployment, wrap up the migration:

  • Shut down the self-hosted server, worker, and Redis instances, along with the previous storefront hosting.
  • Keep a final backup of the self-hosted database, then shut the database down.
  • Shut down the previous file storage, as long as no records still reference its URLs.
  • Remove the previous host's deployment pipeline, secrets, and configuration files from your repository.
  • Rotate any credentials your previous host stored.

Next Steps#

Explore features that weren't available in your self-hosted setup:

Was this guide helpful?
Docs Assistant
For assistance in your development, use Claude Code Plugins or Docs MCP server in Cursor, VSCode, etc...FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break
⇧↵