Skip to content

Deploy an application (docker image) in ECS Fargate, with all network configuration, for multiple running container instances, a load balancer distributing traffic between the containers, auto-scaling of resources, health checks, and logs.

Notifications You must be signed in to change notification settings

CarlosPalaciosC/terraform-ecs

Repository files navigation

Deploy application in ECS Fargate

  • We will be able to run one command to deploy our entire application giving us:

    • A Virtual Private Cloud with private and public subnets
    • Internet Gateway and NatGateway
    • Multiple running container instances
    • A load balancer distributing traffic between the containers
    • Auto scaling of your resources
    • Health checks and logs

To get internet traffic to containers using a load balancer, the load balancer is placed into a public subnet. ECS configures the load balancer to forward traffic to the container tasks in the private subnet: alt text

This configuration allows your tasks in Fargate to be safely isolated from the rest of the internet. They can still initiate network communication with external resources via the NAT gateway, and still receive traffic from the public via the Application Load Balancer that is in the public subnet.

  • All configurations can be changed in:
variables.ft

You can choose your docker image application to deploy in Fargate, changing app_image and app_port in variables.tf

variable "az_count" {
  description = "Number of AZs to cover in a given region"
  default     = "2"
}

variable "app_image" {
  description = "Docker image to run in the ECS cluster"
  default     = "gcr.io/google-samples/hello-app:2.0"
}
  1. Terraform init, plan and validate scripts
terraform init
terraform plan
terraform validate
  1. Apply changes
terraform apply

Output console: Plan: 34 to add, 0 to change, 0 to destroy.

Before to create all resources you can access to application with

curl -v http:/<LOAD_BALANCER_HOSTNAME>/
  1. Remember to destroy all resources to avoid incurring payments
terraform destroy -auto-approve

About

Deploy an application (docker image) in ECS Fargate, with all network configuration, for multiple running container instances, a load balancer distributing traffic between the containers, auto-scaling of resources, health checks, and logs.

Topics

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published