Skip to content

appearance

Choose a theme

Tune the docs for your next build session.

AWS ECS & Copilot CLI

In the last section we used docker compose to run our app locally with a single command: docker compose up. Now that we have a functioning multi-container app, let’s explore how to deploy containerized applications to production on AWS.

AWS provides multiple modern options for running containers:

  1. AWS App Runner — Fully managed service for building and running containerized web applications directly from source or image repositories.
  2. AWS Elastic Container Service (ECS) with Fargate — Serverless compute for containers that provisions and scales Amazon ECS tasks automatically without needing EC2 instances.
  3. AWS Elastic Kubernetes Service (EKS) — Managed Kubernetes on AWS.

In this section, we will look at AWS Elastic Container Service (ECS) running on AWS Fargate, using AWS’s official developer tool: AWS Copilot CLI.

AWS Copilot CLI is the modern, official CLI for building, releasing, and operating production-ready containerized apps on AWS App Runner and AWS ECS Fargate. It automates setting up infrastructure like VPCs, load balancers, security groups, and ECS services using best-practice architecture.

Note on ecs-cli: Earlier versions of AWS tutorials recommended ecs-cli. AWS has officially deprecated ecs-cli in favor of AWS Copilot.

Install the AWS Copilot CLI following the official guide:

  • Mac (Homebrew): brew install aws/tap/copilot-cli
  • Linux: Download the binary from AWS GitHub releases:
    Terminal window
    curl -Lo copilot https://github.com/aws/copilot-cli/releases/latest/download/copilot-linux
    chmod +x copilot
    sudo mv copilot /usr/local/bin/copilot

Verify installation:

Terminal window
$ copilot --version
copilot version: v1.34.0

Ensure you have your AWS CLI configured with active credentials (aws configure).

Inside your project directory containing your Dockerfile, initialize Copilot:

Terminal window
$ copilot init

Copilot will guide you through an interactive prompt:

  • Application name: foodtrucks
  • Workload type: Load Balanced Web Service
  • Service name: web
  • Dockerfile: ./Dockerfile or ./flask-app/Dockerfile

Copilot creates an infrastructure blueprint in a copilot/ directory and sets up your build pipeline.

To launch your service on AWS Fargate:

Terminal window
$ copilot deploy

AWS Copilot will:

  1. Build your Docker container image locally.
  2. Push your image to Amazon ECR (Elastic Container Registry).
  3. Provision an AWS Fargate cluster, VPC, subnets, and Application Load Balancer.
  4. Deploy your container and return a public HTTPS URL.
Terminal window
Deployed service web
Recommended follow-up actions:
- View service status: copilot svc status
- Access your service at: http://foodtrucks-publi-123456789.us-east-1.elb.amazonaws.com

Inspect running containers and view CloudWatch logs straight from your terminal:

Terminal window
# View service status and health
$ copilot svc status
# Stream container logs live
$ copilot svc logs --follow

When you’re finished testing your application, tear down all AWS resources and infrastructure to prevent ongoing charges:

Terminal window
$ copilot app delete --yes
Deleted service web from environment test
Deleted environment test from application foodtrucks
Deleted application foodtrucks

AWS Copilot makes running production containerized applications on AWS simple, secure, and fully automated!