Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

deploy-terraform-aws-ecs

⚠️

The Terraform definitions in this repository are for demo purposes only, and must not be used for production deployments. The IaC code omits many security practices for brevity and simplicity, and most of the tfsec errors are ignored.

Deploying Customers and Orders to AWS Elastic Container Service (ECS) with Terraform

  • Application stack description:

    • Services deployed as Docker Containers to AWS Elastic Container Service (ECS)

    • Docker Images stored in private AWS Elastic Container Registry (ECR)

    • Ingress HTTP traffic via AWS Application Load Balancer (ALB) with path based routing

      • /customer* -→ Customers Service

      • /order* -→ Orders Service

  • Create AWS resources

terraform -chdir=live init
terraform -chdir=live apply
  • Build and push Docker images to AWS Elastic Container Registry (ECR)

export ECR_HOST=758308814218.dkr.ecr.us-east-1.amazonaws.com # Insert your ECR host here
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin $ECR_HOST

export SERVICE_CUSTOMERS_IMAGE=test-45d8-service-customers:latest
docker build --platform=linux/amd64 -t $SERVICE_CUSTOMERS_IMAGE  -f ../service-customers/Dockerfile ..
docker tag $SERVICE_CUSTOMERS_IMAGE $ECR_HOST/$SERVICE_CUSTOMERS_IMAGE
docker push $ECR_HOST/$SERVICE_CUSTOMERS_IMAGE

export SERVICE_ORDERS_IMAGE=test-45d8-service-orders:latest
docker build --platform=linux/amd64 -t $SERVICE_ORDERS_IMAGE -f ../service-orders/Dockerfile ..
docker tag $SERVICE_ORDERS_IMAGE $ECR_HOST/$SERVICE_ORDERS_IMAGE
docker push $ECR_HOST/$SERVICE_ORDERS_IMAGE
  • Go to AWS Console and update ECS task definitions to use new Docker images

  • Update revision variable in [service-orders.tf](live/service-orders.tf) and [service-customers.tf](live/service-customers.tf) to the latest revision of the task definition.

  • Deploy latest revision

terraform -chdir=live apply
  • Get service ingress URLs

terraform -chdir=live output