This guide explains how to build, deploy, and access the name-gen app running on AWS ECS (Fargate) behind an Application Load Balancer (ALB) using GitHub Actions and Terraform.
Services Used:
- Amazon ECR – Stores your Docker images
- Amazon ECS (Fargate) – Runs containers without managing servers
- Application Load Balancer (ALB) – Routes HTTP traffic to your app
- GitHub Actions – Builds & deploys the Docker image automatically
- IAM Roles – Allow ECS to pull images and run tasks
App URL (after deploy):
http://(your-alb-dns-name)
-
Installed Tools
-
AWS Account
- With an IAM user that has permissions for ECR, ECS, ELB, IAM.
AmazonECS_FullAccessAmazonEC2ContainerRegistryFullAccessElasticLoadBalancingFullAccessIAMReadOnlyAccess- Store your AWS credentials in GitHub Secrets:
AWS_ACCESS_KEYAWS_SECRET_ACCESS_KEY
-
GitHub Repository
- Contains:
Dockerfile.github/workflows/deploy.ymlinfra/folder with Terraform setup
- Contains:
Deploy-Docker-Image-To-AWS-ECR
├─ deploy_to_ecr.sh
├─ Dockerfile
├─ ecs-task-def.json
├─ ecs-task.json
├─ index.js
├─ infra
│ ├─ main.tf
│ ├─ outputs.tf
│ └─ variables.tf
├─ package-lock.json
├─ package.json
├─ public
│ ├─ images
│ │ └─ whisper-img.jpg
│ └─ styles
│ └─ main.css
├─ Readme.md
└─ views
└─ index.ejs
-
Build your Docker image:
docker build -t secret-gen:latest . -
Run it locally:
docker run -p 3000:3000 secret-gen:latest
-
Open your browser and visit:
http://localhost:3000
-
Navigate to your
project-repodirectory:cd infra -
Initialize Terraform:
terraform init
-
Apply the configuration:
terraform apply -auto-approve
Terraform will create:
- ECR repository (
name-gen-repo) - ECS cluster & service (
name-gen-cluster,name-gen-service) - Application Load Balancer (ALB)
- Security groups, IAM roles, and networking
Once complete, Terraform will output:
alb_dns_name = name-gen-alb-xxxxxxx.us-east-1.elb.amazonaws.com
ecr_repository_url = $ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/name-gen-repo
-
Authenticate Docker to ECR:
aws ecr get-login-password --region us-east-1 \ | docker login --username AWS --password-stdin $ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com
-
Tag your image:
docker tag name-gen:latest $ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/name-gen-repo:latest -
Push the image:
docker push $ACCOUNT_ID.dkr.ecr.us-east-1.amazonaws.com/name-gen-repo:latest
Whenever you push to the main branch:
-
GitHub Actions will:
- Build the Docker image
- Push it to ECR
- Update the ECS Task Definition
- Deploy the new version to your ECS Fargate service
Workflow file: .github/workflows/deploy.yml
-
Go to the AWS Management Console → EC2 → Load Balancers
-
Find the load balancer named
name-gen-alb -
Copy the DNS name, e.g.:
name-gen-alb-123456789.us-east-1.elb.amazonaws.com -
Open it in your browser:
http://name-gen-alb-123456789.us-east-1.elb.amazonaws.com
🎉 The app should now be running live on ECS Fargate!
aws ecs list-services --cluster name-gen-clusteraws ecs list-tasks --cluster name-gen-clusteraws logs describe-log-groupsWhen you’re done and want to remove all AWS resources:
cd infra
terraform destroy -auto-approveThis will remove the ALB, ECS cluster, ECR, and IAM roles.
| Issue | Possible Fix |
|---|---|
| App not accessible | Check ALB security group allows inbound port 80 |
| Task stuck in PENDING | Ensure subnets and IAM role permissions are correct |
| Image not found | Verify Docker image pushed to correct ECR repo |
| Access denied | Double-check GitHub Secrets (AWS_ACCESS_KEY, AWS_SECRET_ACCESS_KEY) |
| Component | Name |
|---|---|
| AWS Region | us-east-1 |
| ECR Repo | name-gen-repo |
| ECS Cluster | name-gen-cluster |
| ECS Service | name-gen-service |
| Container Port | 300 |
| Public Access | via ALB (port 80) |
Author: EMMANUEL OWUSU-ADDAI