A step-by-step tutorial on how to deploy a Medusa Server on AWS
Tags: aws, deployment, microtica, medusajs
Published: 2022-12-12 14:52:54

Medusa is an open-source, Node.js e-commerce alternative to Shopify. Medusa is composed of three components:

* a headless backend engine that holds all the logic and data of the store and exposes APIs to communicate with the admin and storefront. The Medusa Server

* an admin dashboard that allows store operators to manage their orders and products

* a storefront, which is ultimately an e-commerce website where customers can preview products and make orders

## Why deploy Medusa Server on AWS?

Here are some of the reasons why it would be a good idea to deploy a Medusa.js Server on AWS with Microtica’s template:

* Out-of-the-box serverless infrastructure with Fargate

* Infrastructure and data ownership on your AWS account

* Autoscaling based on application load

* Automated git-push deployments and rollbacks

* Production-ready solution

* Resource monitoring and performance insights in-app

## Getting started

* A Git account. Any provider from GitHub, BitBucket, GitLab, and CodeCommit is supported.

* [Create a Microtica account](https://app.microtica.com/auth/signup?utm_source=devto&utm_medium=blog&utm_campaign=deploy+medusa+on+aws) by signing up with your email or your Git account.

* You need to have an AWS account to be able to deploy a react app to your AWS account. Here you can [sign up for an AWS account](https://aws.amazon.com/).

## Deploy a new Medusa Server

After creating a Microtica account, click the ***Deploy app*** button to land on the Templates page, where you can see a list of all production-ready templates.

[![One-click deploy on Microtica](https://cdn-images-1.medium.com/max/2160/0*yPM4LolCmcwyo2dz)](https://app.microtica.com/templates/new?template=https%3A%2F%2Fraw.githubusercontent.com%2Fmicrotica%2Ftemplates%2Fmaster%2Fmedusa-server%2F.microtica%2Ftemplate.yaml&utm_source=devto&utm_medium=blog&utm_campaign=deploy+medusa+on+aws)

This template creates the following infrastructure resources that will be provisioned on your AWS account:

* VPC, subnets and networking,

* Container infrastructure based on Fargate,

* application load balancer,

* persistent storage,

* S3 bucket,

* Postgres database,

* and Redis (in production mode)

## 1. Create a Git repository

Connect your preferred Git account. Microtica will create a repository on your Git account with a default repo name `medusa-server`.

![Create Git repository in Microtica](https://cdn-images-1.medium.com/max/2000/0*AYA_5Qxh0i5w5API)

## 2. Configure Template

Here you can customize the template for your needs by providing environment variables. Enter an application name and the admin credentials that will be used to create an initial admin user with which you can later sign in to your Medusa Admin.

Select whether you want a production Medusa Server environment or a development one. In production mode, this template will provision managed RDS PostgreSQL and Redis instances. In development mode, the template will use local SQLite and a fake Redis instance.

![Configure the template in Microtica](https://cdn-images-1.medium.com/max/2000/0*20qBNOOAx6dJa7dP)

Environment variables can be updated/added/configured after deployment as well.

## 3. Connect an AWS account

In the last step you can select the environment in which you want to deploy the template. An existing default environment called `development` will be preselected here, or you can create a new environment.

Connect your AWS account when prompted. This process takes only a few seconds, so afterward only choose the region you want to deploy in.

![Connect AWS account in Microtica](https://cdn-images-1.medium.com/max/2000/0*wD5h7C66rTEtoY6R)

## 4. Deploy the Medusa Server template to AWS

Finally, a deployment summary of what will be provisioned on your AWS account is presented.

![Deployment summary in Microtica](https://cdn-images-1.medium.com/max/2000/0*Su2PvCcwaFvO3quD)

Clicking the ***Deploy ***button will trigger a deployment of the template and start creating the infrastructure for a Medusa Server.

It will take around 10 mins for the solution to be deployed on the cloud.

You can follow the build pipeline in real-time by clicking the ***View Logs*** button.

![Building logs in Microtica](https://cdn-images-1.medium.com/max/2656/0*G40LVuTP_RMldAH0)

Once the build process is complete, a new deployment with the infrastructure resources is triggered. You can follow the logs of the deployment process by clicking the ***View deployment*** button, and then selecting the deployment from the list.

![Deployment logs in Microtica](https://cdn-images-1.medium.com/max/2654/0*VCiLvi7cYQWer1sz)

## 5. Preview the environment

After the deployment is finished, navigate to *Resources* → *[AppName] (Medusa in our case)* → *Overview*, and under *Resource Outputs* you should see the **AccessUrl**.

This is the server url that you can use to access API endpoints. Try getting the list of products using the endpoint `/store/products`.

![Access API endpoints](https://cdn-images-1.medium.com/max/3200/0*T7LKU9ZJHFb4SU8f)

The image below shows how your environment should look after deploying both templates.

![Environment in Microtica](https://cdn-images-1.medium.com/max/3200/0*bz9gEweLAoAaq3r1)

## Bonus: Cleanup

To remove all the resources created on your AWS account, navigate to your environment → *Environment Settings* → *Infrastructure*, and you’ll see the ***Undeploy*** section.

This will clean up the resources created in AWS, but you will still have the configuration in Microtica in case you want to deploy it in the cloud again.

## Deploy an existing Medusa Server

If you already have an existing Medusa server repository that you want to migrate to AWS, there are several changes you need to make to your source code. You can follow [our documentation](https://docs.microtica.com/medusa-server?utm_source=devto&utm_medium=blog&utm_campaign=deploy+medusa+on+aws) to configure and import your Medusa server repo code.