Creating EC2 based ECS cluster with Terraform


Amazon ECS

  1. VPC which contains (subnets,internet_gateway,nat_gateway,route_tables)
  2. Security_groups (filter out the traffic)
  3. Launch configuration (contains metadata of an instance to be launched)
  4. Autoscaling group (make desired instances up)
  5. Application Load Balancer (helps to distribute the traffic)
  6. Roles ( permissions to be given for interaction with another service)
  7. ECS cluster
  8. ECS task_definitions
  9. ECS service



Security Groups

Launch Configuration

Autoscaling Group

Load Balancer

IAM Roles

ECS cluster

Task Definition

  • The Docker image to use with each container in your task
  • How much CPU and memory to use with each task or each container within a task
  • The launch type to use, which determines the infrastructure on which your tasks are hosted
  • The Docker networking mode to use for the containers in your task
  • The logging configuration to use for your tasks
  • Whether the task should continue to run if the container finishes or fails
  • The command the container should run when it is started
  • Any data volumes that should be used with the containers in the task
  • The IAM role that your tasks should use

ECS Service

Deploying the code

$terraform plan
$terraform apply 
$terraform destroy



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store