Listen to this Post

AWS offers multiple options for running container-based applications, with Elastic Container Service (ECS) and Elastic Kubernetes Service (EKS) being popular choices. While EKS provides advanced Kubernetes features, it comes with an ongoing control plane cost. ECS, however, offers a cost-effective orchestration layer.
This article explores deploying a Node.js app to Amazon ECS using GitHub Actions for CI/CD automation and Terraform for Infrastructure as Code (IaC).
You Should Know:
1. Prerequisites
- AWS Account with IAM permissions
- GitHub Account
- Terraform installed (
brew install terraformorsudo apt install terraform) - Docker installed (
sudo apt install docker.io) - Node.js app (sample app available here)
2. Setting Up Terraform for ECS
Create a `main.tf` file for ECS infrastructure:
provider "aws" {
region = "us-east-1"
}
resource "aws_ecs_cluster" "nodejs_cluster" {
name = "nodejs-ecs-cluster"
}
resource "aws_ecs_task_definition" "nodejs_task" {
family = "nodejs-task"
network_mode = "awsvpc"
requires_compatibilities = ["FARGATE"]
cpu = "256"
memory = "512"
execution_role_arn = aws_iam_role.ecs_task_execution_role.arn
container_definitions = jsonencode([{
name = "nodejs-app",
image = "YOUR_ECR_REPO_URL:latest",
portMappings = [{
containerPort = 3000,
hostPort = 3000
}]
}])
}
3. Configuring GitHub Actions for CI/CD
Create `.github/workflows/deploy.yml`:
name: Deploy to ECS on: push: branches: [ main ] jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - run: docker build -t nodejs-app . - run: aws ecr get-login-password | docker login --username AWS --password-stdin YOUR_ECR_REPO_URL - run: docker push YOUR_ECR_REPO_URL:latest - run: terraform init && terraform apply -auto-approve
4. Deploying & Verifying
- Push changes to GitHub (
git push origin main) - Monitor GitHub Actions logs
- Verify deployment in AWS ECS Console:
aws ecs list-tasks --cluster nodejs-ecs-cluster
5. Essential AWS & Linux Commands
- Check ECS Tasks:
aws ecs describe-tasks --cluster nodejs-ecs-cluster --tasks TASK_ARN
- View CloudWatch Logs:
aws logs get-log-events --log-group-name /ecs/nodejs-task --log-stream-name STREAM_NAME
- Destroy Infrastructure:
terraform destroy -auto-approve
What Undercode Say:
Deploying with ECS + GitHub Actions + Terraform provides a scalable, automated, and cost-efficient approach for containerized apps. While EKS offers deeper Kubernetes integration, ECS simplifies orchestration for smaller to medium workloads.
Prediction:
As serverless containers (AWS Fargate) gain traction, more teams will adopt GitHub Actions + Terraform for end-to-end IaC automation, reducing manual cloud management.
Expected Output:
- Successful ECS deployment
- Automated CI/CD via GitHub Actions
- Terraform-managed infrastructure
Reference: Deploy Node.js App to Amazon ECS
References:
Reported By: Darryl Ruggles – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅


