
CloudFormation ECS Stack
Full ECS Fargate deployment with ALB, auto-scaling, and CloudWatch.
A nested CloudFormation stack deploying a containerised application on ECS Fargate. Includes an Application Load Balancer, target groups, service auto-scaling based on CPU and memory, CloudWatch log groups, and scoped IAM roles.
Tech Stack
Features
- Nested stacks: networking, ECS cluster, service, IAM
- ALB with HTTPS listener and ACM certificate
- Step scaling policies on CPU > 70% and Memory > 80%
- CloudWatch Container Insights enabled
- KMS-encrypted log groups
Stack Structure
The root stack references nested stacks via S3 URLs. `network.yaml` creates the VPC and subnets. `cluster.yaml` provisions the ECS cluster. `service.yaml` defines the task definition, service, and ALB. `iam.yaml` scopes execution and task roles.
Deployment
Upload the nested templates to an S3 bucket, then deploy the root stack: `aws cloudformation deploy --template-file root.yaml --stack-name my-app --capabilities CAPABILITY_IAM --parameter-overrides ImageUri=<ecr-uri>`.
Parameters
Key parameters: `ImageUri` (ECR image URL), `DesiredCount` (default 1), `Cpu` (256/512/1024), `Memory` (512/1024/2048), `CertificateArn` (ACM ARN for HTTPS), `Environment` (dev/stage/prod).
File Structure
- root.yaml
- stacks/
- network.yaml
- cluster.yaml
- service.yaml
- iam.yaml
- scripts/
- deploy.sh
- upload-templates.sh
- parameters.json
- .gitlab-ci.yml
- README.md