This project demonstrates how to deploy a MedusaJS headless commerce backend on AWS using:
- Terraform for infrastructure provisioning
- Docker for containerization
- ECS Fargate for serverless container hosting
- GitHub Actions for CI/CD automation
My-Medusa-Store/
├── my-medusa-store/ # Medusa backend code
│ ├── Dockerfile # Docker config for Medusa backend
│ └── Terraform/ # Terraform scripts for AWS infra
│ ├── main.tf
│ ├── variables.tf
│ ├── outputs.tf
│ ├── terraform.tfvars
│ └── ...
├── my-medusa-store-storefront/ # (Optional) Frontend (not covered here)
└── .github/
└── workflows/
└── main.yml # GitHub Actions CI/CD pipeline
- ✅ VPC (with subnets, route tables, and IGW)
- ✅ ECS Cluster (Fargate)
- ✅ Task Definition
- ✅ Security Groups
- ✅ IAM Roles (ECS execution and task)
- ✅ ECR Repository (for Docker image)
- ✅ Application Load Balancer
git clone https://github.com/trivediayush/Medusa-Store.git
cd Medusa-Store
aws_region = "eu-north-1"
db_password = "your-secure-password"
ecr_repo_name = "your-ecr-repo-name"
medusa_port = 9000
aws configure
The Medusa backend is containerized using a Dockerfile located inside my-medusa-store/.
FROM node:18
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build
EXPOSE 9000
CMD ["npm", "start"]
cd my-medusa-store/Terraform
terraform init
terraform plan -var-file="terraform.tfvars"
terraform apply -auto-approve -var-file="terraform.tfvars"
The file .github/workflows/main.yml automates the deployment process:
- ✅ Checks out code
- ✅ Builds Docker image
- ✅ Pushes to ECR
- ✅ Runs Terraform to provision/update infra
Name
Description
AWS_ACCESS_KEY_ID
AWS access key
AWS_SECRET_ACCESS_KEY
AWS secret key
DB_PASSWORD
RDS or service DB password
✅ CI/CD triggers on main branch push
- Uses ECS Fargate – No EC2 management
- Infra is idempotent via Terraform
- Secure secrets management via GitHub
- Highly scalable & production ready architecture
Made with ❤️ by Ayush Trivedi
