This template deploys a Dockerized web application on AWS ECS Fargate with a public-facing Application Load Balancer.
This template provides the necessary infrastructure to run a containerized application on a scalable, serverless platform. It includes:
- A VPC with public and private subnets.
- An Application Load Balancer to distribute traffic.
- An ECS Fargate Service to run your container.
- An ECR Repository to store your Docker image.
- All necessary Security Groups and IAM Roles.
The infrastructure code is located in the infra/ directory and is managed by Terraform. The application code and Dockerfile are located in the app/ directory.
┌─────────────────────────────────────────────────────────────────┐
│ │
│ ┌──────────────────── VPC (10.0.0.0/16) ──────────────────┐ │
│ │ │ │
│ │ ┌─── Public Subnets ───┐ ┌─── Private Subnets ───┐ │ │
│ │ │ │ │ │ │ │
│ │ │ ┌─────────────────┐ │ │ ┌──────────────────┐ │ │ │
│ │ │ │ │ │ │ │ ECS Fargate │ │ │ │
│ │ │ │ Application │─┼────┼─▶│ Service │ │ │ │
│ │ │ │ Load Balancer │ │ │ │ (Your App) │ │ │ │
│ │ │ │ │ │ │ └──────────────────┘ │ │ │
│ │ │ └────────┬────────┘ │ │ │ │ │ │
│ │ │ │ │ │ ▼ │ │ │
│ │ └───────────┼──────────┘ │ ┌──────────────────┐ │ │ │
│ │ │ │ │ CloudWatch Logs │ │ │ │
│ │ ┌───────────┼──────────┐ │ └──────────────────┘ │ │ │
│ │ │ │ │ │ │ │ │
│ │ │ ┌────────▼────────┐ │ └────────────────────────┘ │ │
│ │ │ │ NAT Gateway │─┼──────────────┐ │ │
│ │ │ └─────────────────┘ │ │ │ │
│ │ │ │ │ │ │
│ │ └──────────────────────┘ │ │ │
│ │ │ │ │
│ └────────────────────────────────────────┼─────────────────┘ │
│ │ │
│ ┌────────────────────────────────────────┼─────────────────┐ │
│ │ Internet Gateway │ │ │
│ └────────────────────────────────────────┼─────────────────┘ │
│ │ │
└───────────────────────────────────────────┼────────────────────┘
│
┌────────▼────────┐
│ ECR Registry │
│ (Docker Images)│
└─────────────────┘
Traffic Flow:
- User requests hit the Application Load Balancer (ALB) in public subnets
- ALB forwards traffic to ECS Fargate tasks running in private subnets
- ECS tasks pull Docker images from ECR
- NAT Gateway enables outbound internet access for private resources
- All logs are sent to CloudWatch Logs for monitoring
For rapid deployment with step-by-step guidance, see QUICKSTART.md.
# 1. Verify prerequisites
make bootstrap
# 2. Configure environment
# Edit envs/dev/terraform.tfvars with your settings
# 3. Deploy infrastructure
make init ENV=dev
make apply ENV=dev
# 4. Build and push Docker image
make build
make push ECR_REPOSITORY_URL=$(cd infra && terraform output -raw ecr_repository_url)
# 5. Access your application
make outputs ENV=devFor detailed deployment instructions, see DEPLOYMENT.md.
.
├── app/ # Application code
│ ├── Dockerfile # Container definition
│ └── app.py # Sample Flask application
├── envs/ # Environment configurations
│ ├── dev/ # Development settings
│ ├── staging/ # Staging settings
│ └── prod/ # Production settings
├── infra/ # Terraform infrastructure
│ ├── backend.tf # State configuration
│ ├── data.tf # Data sources
│ ├── main.tf # Core infrastructure
│ ├── outputs.tf # Output values
│ ├── providers.tf # Provider configuration
│ └── variables.tf # Input variables
├── examples/ # Usage examples
├── QUICKSTART.md # Quick start guide
├── DEPLOYMENT.md # Detailed deployment guide
├── Makefile # Automation commands
└── README.md # This file
The template supports three pre-configured environments:
| Environment | CPU/Memory | Tasks | Auto-scaling | Container Insights | Est. Cost/Month |
|---|---|---|---|---|---|
| dev | 256/512 | 1 | Disabled | Disabled | $65-70 |
| staging | 512/1024 | 2 | Enabled | Enabled | $100-120 |
| prod | 1024/2048 | 3+ | Enabled | Enabled | $200-250+ |
make help # Show all available commands
make bootstrap # Check required tools
make init ENV=dev # Initialize Terraform
make plan ENV=dev # Plan infrastructure changes
make apply ENV=dev # Deploy infrastructure
make destroy ENV=dev # Destroy infrastructure
make build # Build Docker image
make push # Push image to ECR
make outputs ENV=dev # Show Terraform outputs
make validate # Validate Terraform code
make security # Run security scans
make test ENV=dev # Run integration tests- Run
make helpto see all available commands and get help with common tasks - Open a support ticket at https://senora.dev/NewTicket
This template is maintained by Senora.dev.