AWS Copilot

Recommended

The easiest way to deploy containers to AWS ECS Fargate

What is AWS Copilot?

AWS Copilot is a command-line tool that simplifies deploying and managing containerized applications on AWS. Instead of manually configuring VPCs, ECS clusters, load balancers, and IAM roles, Copilot handles everything with simple commands.

Perfect for Beginners

Copilot is ideal if you want to deploy quickly without learning all the underlying AWS services. Its like having an expert configure everything for you.

Installation

Install using Homebrew:

Terminal
$brew install aws/tap/copilot-cli

Verify Installation

Terminal
$copilot --version
copilot version: v1.32.0

Copilot Concepts

ConceptWhat It IsExample
ApplicationA collection of related services"my-app"
EnvironmentA deployment stage"staging", "production"
ServiceA containerized workload"frontend", "api"

Quick Deploy Guide

1

Initialize Application

Run this in your project directory with a Dockerfile:

2

Create an Environment

This creates your VPC, ECS cluster, and load balancer:

3

Deploy Your Service

Build, push to ECR, and deploy to ECS Fargate:

Terminal
$copilot init
Application name: my-app
Workload type: Load Balanced Web Service
Service name: frontend
Dockerfile: ./Dockerfile
Terminal
$copilot env init --name staging
Environment name: staging
Credential source: [profile default]
Default environment configuration? Yes
Terminal
$copilot deploy
Building your container image...
Pushing to ECR...
Creating CloudFormation stack...

✔ Deployed frontend to staging.

URL: http://my-app-staging-123456.ap-southeast-1.elb.amazonaws.com

First Deploy Takes Time

The first deployment takes 10-15 minutes because Copilot creates all the infrastructure. Subsequent deployments are much faster (2-5 minutes).

Useful Commands

CommandPurpose
copilot svc statusCheck service health and URL
copilot svc logsView application logs
copilot svc execSSH into a running container
copilot app deleteRemove everything (careful!)

What Copilot Creates

Behind the scenes, Copilot provisions:

  • VPC with public/private subnets
  • ECS Cluster in Fargate mode
  • Application Load Balancer
  • ECR Repository for your images
  • CloudWatch Log Groups
  • IAM Roles and Policies
  • Security Groups

Service Manifest

Copilot uses manifest files to configure your service. Choose the right level:

A minimal manifest for learning and development:

copilot/frontend/manifest.yml
name: frontend
type: Load Balanced Web Service

http:
  path: '/'

image:
  build: Dockerfile
  port: 3000

cpu: 256
memory: 512
count: 1

variables:
  NODE_ENV: production

Missing for Production

  • No health check endpoint
  • Single task (no high availability)
  • No auto-scaling
  • No HTTPS configured

AWS Services Configuration

If your app uses AWS services like S3, SQS, or CloudWatch, you need to configure environment variables. Choose the appropriate method for your use case:

Security Warning

Never commit AWS credentials to Git. Add copilot/frontend/manifest.yml to your .gitignore when using plain text credentials for POC testing.

Quick setup for testing. Put credentials directly in the manifest. Not recommended for production - rotate these credentials after testing!

copilot/frontend/manifest.yml
# Full working manifest for POC with AWS services
name: frontend
type: Load Balanced Web Service

http:
  path: '/'
  healthcheck:
    path: '/api/health'
    healthy_threshold: 2
    unhealthy_threshold: 3
    interval: 15s
    timeout: 10s

image:
  build: Dockerfile
  port: 3000

cpu: 256
memory: 512
count: 1

exec: true  # Enable ECS Exec for debugging

variables:
  # App Configuration
  HOSTNAME: "0.0.0.0"
  PORT: "3000"
  NODE_ENV: production

  # AWS Configuration - CHANGE THESE TO YOUR VALUES
  AWS_REGION: "us-east-1"
  AWS_S3_BUCKET_NAME: "your-bucket-name"
  AWS_SQS_QUEUE_URL: "https://sqs.us-east-1.amazonaws.com/123456789012/your-queue-name"
  AWS_CLOUDWATCH_LOG_GROUP: "your-log-group-name"

  # AWS Credentials - REPLACE WITH YOUR KEYS (rotate after testing!)
  AWS_ACCESS_KEY_ID: "YOUR_ACCESS_KEY_ID"
  AWS_SECRET_ACCESS_KEY: "YOUR_SECRET_ACCESS_KEY"

logging:
  retention: 7

Don't Forget!

  1. 1. Add copilot/frontend/manifest.yml to .gitignore
  2. 2. Replace all placeholder values with your actual AWS resource IDs
  3. 3. Rotate credentials in IAM console after testing

Deploy with AWS Services

Terminal
$copilot svc deploy -n frontend -e staging
Building your container image...
Pushing to ECR...
Deploying to ECS...
✔ Deployed frontend to staging.

Verify AWS Integration

After deployment, navigate to your app's /demos page. If configured correctly, you'll see "Live AWS" badges instead of "Mock Mode".

⚠️ Cost Awareness - READ THIS

Running an ECS Fargate service with ALB costs approximately $30-50/month for a small workload. Major cost components:

  • ALB: ~$16/month (fixed cost while running)
  • Fargate: ~$15-30/month (depends on vCPU/memory)
  • NAT Gateway: ~$32/month if using private subnets

Always delete resources when done: copilot app delete
See our Costs & Cleanup Guide for detailed breakdown and cleanup instructions.

AWS Deployment Guide — Built with Next.js