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:
- AWS App Runner — Fully managed service for building and running containerized web applications directly from source or image repositories.
- AWS Elastic Container Service (ECS) with Fargate — Serverless compute for containers that provisions and scales Amazon ECS tasks automatically without needing EC2 instances.
- 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.
What is AWS Copilot?
Section titled “What is AWS Copilot?”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 recommendedecs-cli. AWS has officially deprecatedecs-cliin favor of AWS Copilot.
Installing AWS Copilot
Section titled “Installing 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-linuxchmod +x copilotsudo mv copilot /usr/local/bin/copilot
Verify installation:
$ copilot --versioncopilot version: v1.34.0Deploying with Copilot
Section titled “Deploying with Copilot”Ensure you have your AWS CLI configured with active credentials (aws configure).
1. Initialize Your Application
Section titled “1. Initialize Your Application”Inside your project directory containing your Dockerfile, initialize Copilot:
$ copilot initCopilot will guide you through an interactive prompt:
- Application name:
foodtrucks - Workload type:
Load Balanced Web Service - Service name:
web - Dockerfile:
./Dockerfileor./flask-app/Dockerfile
Copilot creates an infrastructure blueprint in a copilot/ directory and sets up your build pipeline.
2. Deploy to Environment
Section titled “2. Deploy to Environment”To launch your service on AWS Fargate:
$ copilot deployAWS Copilot will:
- Build your Docker container image locally.
- Push your image to Amazon ECR (Elastic Container Registry).
- Provision an AWS Fargate cluster, VPC, subnets, and Application Load Balancer.
- Deploy your container and return a public HTTPS URL.
✔ Deployed service webRecommended follow-up actions: - View service status: copilot svc status - Access your service at: http://foodtrucks-publi-123456789.us-east-1.elb.amazonaws.comMonitoring & Status
Section titled “Monitoring & Status”Inspect running containers and view CloudWatch logs straight from your terminal:
# View service status and health$ copilot svc status
# Stream container logs live$ copilot svc logs --followCleanup
Section titled “Cleanup”When you’re finished testing your application, tear down all AWS resources and infrastructure to prevent ongoing charges:
$ copilot app delete --yes✔ Deleted service web from environment test✔ Deleted environment test from application foodtrucks✔ Deleted application foodtrucksAWS Copilot makes running production containerized applications on AWS simple, secure, and fully automated!