Deploy a Medusa Server on AWS with Microtica

Marija N. - Jan 16 '23 - - Dev Community

Medusa is an open source composable commerce platform built for developers. Its architecture is flexible enabling users to build bespoke commerce solutions.

Medusa is composed of three components:

  1. A headless backend engine that holds all the logic and data of the store and exposes APIs to communicate with the admin and storefront,
  2. An admin dashboard that allows store operators to manage their orders and products, and
  3. A storefront, which is ultimately an ecommerce website where customers can preview products and make orders.

What is Microtica?

Microtica is a developer self-service platform that enables you to self-host open source solutions on AWS (Amazon Web Services) without being a cloud expert.

The platform provides production-ready templates for development frameworks and solutions, so you can get started fast and be free from the friction of dealing with the underlying cloud complexities.

Using the templates, you can deliver on your own AWS account and deploy applications/services on Amazon EKS (Elastic Kubernetes Service).

Why Should You 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
  • Auto-scaling based on application load
  • Automated git-push deployments and rollbacks
  • Production-ready solution
  • Resource monitoring and performance insights in-app

Prerequisites

To follow through with this tutorial, here’s a list of things you should have/do.

  • Have a Git account; any provider from GitHub, BitBucket, GitLab, and CodeCommit is supported.
  • Create a Microtica account by signing up with your email or your Git account.
  • Have an AWS account to be able to deploy a React app to your AWS account. You can sign up for an AWS account here.

Deploy a New Medusa Server

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

https://res.cloudinary.com/practicaldev/image/fetch/s--j8ltzfzT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2160/0%2AyPM4LolCmcwyo2dz

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
  • Redis (in production mode)

The steps to deploying a new Medusa server are outlined below.

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.

https://res.cloudinary.com/practicaldev/image/fetch/s--7Vz9dgjI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2AAYA_5Qxh0i5w5API

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.

https://res.cloudinary.com/practicaldev/image/fetch/s--hzA-Asi4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2A20qBNOOAx6dJa7dP

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

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 afterwards, only choose the region you want to deploy in.

https://res.cloudinary.com/practicaldev/image/fetch/s--wIJw3JpW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2AwD5h7C66rTEtoY6R

Deploy the Medusa Server Template to AWS

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

https://res.cloudinary.com/practicaldev/image/fetch/s--xprIPGyZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2ASu2PvCcwaFvO3quD

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

It will take about 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.

https://res.cloudinary.com/practicaldev/image/fetch/s--fuXB293j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2656/0%2AG40LVuTP_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.

https://res.cloudinary.com/practicaldev/image/fetch/s--Wq6QxO0g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2654/0%2AVCiLvi7cYQWer1sz

Preview the Environment

After the deployment is finished, navigate to Resources → AppName → 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.

https://res.cloudinary.com/practicaldev/image/fetch/s--eg5JOtmB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3200/0%2AT7LKU9ZJHFb4SU8f

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

https://res.cloudinary.com/practicaldev/image/fetch/s--WeEFNNF8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3200/0%2Abz9gEweLAoAaq3r1

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 the documentation to configure and import your Medusa server repo code.

Should you have any issues or questions related to Medusa, then feel free to reach out to the Medusa team via Discord.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player