Deploying Medusa Backend on AWS with Terraform and GitHub Actions

Introduction

In today’s world of headless commerce, developers need reliable backends that can scale with demand. Medusa is an open-source headless commerce engine that lets you build customizable e-commerce platforms.

In this project, I automated the deployment of Medusa on AWS ECS (Fargate) using Terraform for infrastructure provisioning and GitHub Actions for CI/CD. This means with a single push to GitHub, Terraform provisions the infrastructure, Docker builds the image, and Medusa is deployed seamlessly on AWS.

πŸ‘‰ Full code is available on GitHub: Medusa Project Repo


πŸ—οΈ Architecture Overview

Here’s the cloud infrastructure we provision using Terraform:

  • AWS ECS (Fargate) – Runs the Medusa backend in containers

  • Amazon ECR – Stores Medusa Docker images

  • Application Load Balancer (ALB) – Routes traffic to ECS tasks

  • VPC with Subnets – Secure networking setup

  • IAM Roles – Permissions for ECS and GitHub Actions

  • GitHub Actions – Automates build β†’ push β†’ deploy workflow


πŸ“‚ Project Structure

medusa-project/
β”œβ”€β”€ vpc.tf
β”œβ”€β”€ ecs.tf
β”œβ”€β”€ alb.tf
β”œβ”€β”€ iam.tf
β”œβ”€β”€ ecr.tf
β”œβ”€β”€ security-group.tf
β”œβ”€β”€ provider.tf
β”œβ”€β”€ variable.tf
β”œβ”€β”€ output.tf
β”œβ”€β”€ data.tf
β”œβ”€β”€ taskdefinition.json
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ package.json
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── deploy.yml
└── README.md

βš™οΈ Prerequisites

  • AWS Account with IAM user (programmatic access)

  • GitHub repository

  • Terraform installed

  • AWS CLI installed & configured

  • Docker installed


πŸ”‘ GitHub Secrets

Before using GitHub Actions, add the following secrets in your repository:

Secret NameDescription
AWS_ACCESS_KEY_IDAWS IAM Access Key
AWS_SECRET_ACCESS_KEYAWS IAM Secret
AWS_REGIONe.g. us-east-1
ECR_REPOSITORYName of your ECR repo
ECS_TASK_DEFINITIONTask definition name
ECS_CLUSTER_NAMEECS cluster name
ECS_SERVICE_NAMEECS service name

πŸš€ Steps to Deploy

1. Clone the Repository

git clone https://github.com/Harshalv21/Terraform-Projects.git
cd Medusa-project

2. Initialize Terraform

terraform init

3. Plan Infrastructure

terraform plan

4. Apply Infrastructure (⚠️ will incur AWS charges)

terraform apply

5. Trigger GitHub Actions

Push changes to main branch β†’ GitHub Actions workflow (deploy.yml) will:

  1. Build Docker image

  2. Push to Amazon ECR

  3. Update ECS service with the new Medusa task


πŸ› οΈ Customization (if you want)

  • Modify Dockerfile and package.json for your Medusa configuration.

  • Extend Terraform code to include RDS (Postgres), S3, or Route53 for DNS.

  • Add monitoring (CloudWatch, Prometheus) for production use.


βœ… Project Status

  • Terraform infra files βœ…

  • GitHub Actions CI/CD βœ…

  • Deployment workflow ready βœ…

  • Deployment skipped in repo (to avoid AWS charges) ⚠️


πŸ’‘ Key Learnings

  • Infrastructure as Code (IaC) with Terraform makes deployment reproducible.

  • GitHub Actions enables seamless CI/CD pipelines for AWS deployments.

  • Medusa can be containerized and deployed like any modern microservice.


πŸ”— Resources

  • GitHub Repo

  • Medusa Docs

  • Terraform AWS Provider

  • GitHub Actions Docs

0
Subscribe to my newsletter

Read articles from HARSHAL VERNEKAR directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

HARSHAL VERNEKAR
HARSHAL VERNEKAR

πŸš€ Aspiring DevOps & Cloud Engineer with a strong foundation in cloud platforms (AWS), infrastructure automation, and container orchestration tools like Docker and Kubernetes. I’m passionate about building reliable, scalable, and secure cloud-native applications. πŸ”§ Currently building real-world projects using Terraform, Ansible, Jenkins, GitHub Actions, and EKS to understand how modern infrastructure is deployed, managed, and monitored. I enjoy breaking things (safely), debugging, and learning from hands-on experience. πŸ“¦ Comfortable working with: AWS (EC2, S3, IAM, VPC, EKS) Docker, Kubernetes (Minikube & EKS) CI/CD tools like Jenkins & GitHub Actions IaC tools like Terraform & Ansible Monitoring with Prometheus & Grafana Linux, Bash, Git, and Networking fundamentals πŸ’‘ Always learning β€” currently exploring deeper concepts in Kubernetes workloads, Helm, and scaling best practices. πŸ” Open to DevOps, Cloud, or SRE roles where I can grow, contribute, and solve real-world problems.