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 Name | Description |
AWS_ACCESS_KEY_ID | AWS IAM Access Key |
AWS_SECRET_ACCESS_KEY | AWS IAM Secret |
AWS_REGION | e.g. us-east-1 |
ECR_REPOSITORY | Name of your ECR repo |
ECS_TASK_DEFINITION | Task definition name |
ECS_CLUSTER_NAME | ECS cluster name |
ECS_SERVICE_NAME | ECS 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:
Build Docker image
Push to Amazon ECR
Update ECS service with the new Medusa task
π οΈ Customization (if you want)
Modify
Dockerfile
andpackage.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
Medusa Docs
Terraform AWS Provider
GitHub Actions Docs
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.