/ecs_loadbalancing_demo

Demo Terraform scripts to create an ECS + Load Balancer setup

Primary LanguageHCL

ECS + ALB/ELB

This repo contains two examples of using Terraform to configure Amazon Elastic Container Service; one for use with Classic Elastic Load Balancer, and a second one using the newer Application Load Balancer. Each example is in it's own folder, elb_classic and alb, respectively.

###Disclaimer / Warnings

  • Using either of these will spin up real infrastructure on Amazon. You are responsible for any charges that occur.
  • These examples are meant to demonstrate connecting Elastic Load Balancers to containers running on ECS, and is not in anyway meant to reflect a "production use case". I assume no responsibility, and you use at your own risk.

Steps:

  1. cd into the desired folder
  2. uncomment and configure your access key / secret in the provider block
  3. terraform plan to preview the changes
  4. terraform apply
  5. check out https://us-west-2.console.aws.amazon.com/ecs/home and see the specifics of your ECS cluster
  6. for Classic, you should see that one count of the task could not be placed due to the restriction of Service+Port+Instance
  7. for the new ALB, you'll see all 3 tasks running, with one ECS Instance running two counts of the task

The DNS entry for the respective load balancer will be output and you can hit that directly. To hit an instance specifically, you'll need the Instance IP and to know the port. For the classic example that's 8080. For the ALB example, you'll need to look up which dynamic port it was given in the AWS console.

Both setups create about the same resources, the main difference being the aws_alb and aws_alb_target_group resources.

Requirements:

  • AWS credentials either in the environment, or edit the provider block
  • an ssh key setup at ~/.ssh/id_rsa2.pub