Skip to content

Senora-dev/template-complete-ecs

Repository files navigation

ECS Fargate Template

This template deploys a Dockerized web application on AWS ECS Fargate with a public-facing Application Load Balancer.

Overview

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.

Architecture

┌─────────────────────────────────────────────────────────────────┐
│                                                                 │
│  ┌──────────────────── 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:

  1. User requests hit the Application Load Balancer (ALB) in public subnets
  2. ALB forwards traffic to ECS Fargate tasks running in private subnets
  3. ECS tasks pull Docker images from ECR
  4. NAT Gateway enables outbound internet access for private resources
  5. All logs are sent to CloudWatch Logs for monitoring

Quick Start

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=dev

For detailed deployment instructions, see DEPLOYMENT.md.

Project Structure

.
├── 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

Environment Configuration

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+

Available Commands

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

Support


This template is maintained by Senora.dev.

About

Deploy a containerized app on ECS Fargate with an ALB, VPC, ECR, and all required infrastructure - fully wired and production-ready with Terraform.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors