Browse the Repo

file-type-icondata-stores
file-type-iconlambda
file-type-iconmgmt
file-type-iconnetworking
file-type-iconsecurity
file-type-iconservice-templates
file-type-iconservices
file-type-iconasg-service
file-type-iconbeanstalk-service
file-type-iconecs-cluster
file-type-iconecs-service-with-alb
file-type-iconcontainer-definition
file-type-iconmigration_guides
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvariables.tf
file-type-iconeks-cluster
file-type-iconeks-core-services
file-type-iconk8s-namespace
file-type-iconk8s-service
file-type-iconstatic-website
file-type-icontls-scripts
file-type-icon.gitignore
file-type-iconCODEOWNERS
file-type-iconREADME.md

Browse the Repo

file-type-icondata-stores
file-type-iconlambda
file-type-iconmgmt
file-type-iconnetworking
file-type-iconsecurity
file-type-iconservice-templates
file-type-iconservices
file-type-iconasg-service
file-type-iconbeanstalk-service
file-type-iconecs-cluster
file-type-iconecs-service-with-alb
file-type-iconcontainer-definition
file-type-iconmigration_guides
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvariables.tf
file-type-iconeks-cluster
file-type-iconeks-core-services
file-type-iconk8s-namespace
file-type-iconk8s-service
file-type-iconstatic-website
file-type-icontls-scripts
file-type-icon.gitignore
file-type-iconCODEOWNERS
file-type-iconREADME.md
Sample Infrastructure Modules

Sample Infrastructure Modules

Sample infrastructure-modules repo (multi-account setup) for fictional company Acme.

Code Preview

Preview the Code

mobile file icon

README.md

down

ECS Service With ALB Module

This Terraform Module deploys the ECS Service With ALB ECS Service on top of an ECS Cluster. It uses an existing Application Load Balancer (ALB) in front of the service to route traffic between the Docker containers.

How do you use this module?

  • See the root README for instructions on using Terraform modules.
  • See variables.tf for all the variables you can set on this module.

What is an ECS Cluster?

To use ECS, you first deploy one or more EC2 Instances into a "cluster". The ECS scheduler can then deploy Docker containers across any of the instances in this cluster. Each instance needs to have the Amazon ECS Agent installed so it can communicate with ECS and register itself as part of the right cluster.

What is an ECS Service?

To run Docker containers with ECS, you first define an ECS Task, which is a JSON file that describes what container(s) to run, the resources (memory, CPU) those containers need, the volumes to mount, the environment variables to set, and so on. To actually run an ECS Task, you define an ECS Service, which can:

  1. Deploy the requested number of Tasks across an ECS cluster based on the desired_number_of_tasks input variable.
  2. Restart tasks if they fail.
  3. Route traffic across the tasks with an optional Elastic Load Balancer (ELB). To use an ELB, set is_associated_with_elb to true and pass in the ELB details using the elb_name, elb_container_name, and elb_container_port input variables.

What is an ALB?

An Application Load Balancer is a "Layer 7" load balancer managed by AWS that forwards incoming requests to the ECS Tasks (Docker containers) in your ECS Service which are running in your ECS Cluster.

It automatically discovers new ECS Tasks as they launch. A single ALB is shared among potentially many ECS Services.

Core concepts

For more info on ECS Services the ECS Cluster, and the ALB, check out the ecs-cluster and ecs-service-with-alb documentation in the module-ecs repo, and the alb module in the module-load-balancer repo.

Questions? Ask away.

We're here to talk about our services, answer any questions, give advice, or just to chat.

Ready to hand off the Gruntwork?