AWS Copilot CLI Documentation
repository·mainline·Indexed 25 days ago
https://github.com/aws/copilot-cliA tool for developers to build, release, and operate production-ready containerized applications on AWS App Runner or Amazon ECS on AWS Fargate. The CLI provides command groups for initializing applications, managing environments and services, handling storage and secrets, and deploying via CI/CD pipelines. Note: AWS Copilot CLI will reach end-of-support on June 12, 2026.
What's inside AWS Copilot CLI
- AWS Copilot CLI is a tool designed to build, release, and operate production-ready containerized applications using AWS App Runner and Amazon ECS on AWS Fargate. It manages the entire application development lifecycle, from initial development to pushing to staging environments and releasing to production.
Overview of AWS Copilot CLI capabilities
mainlineAWS Copilot CLI is a developer tool designed to build, release, and operate production-ready containerized applications on AWS App Runner and Amazon ECS on AWS Fargate. It manages the entire application lifecycle, including:
- Getting started with new applications
- Pushing code to staging environments
- Releasing applications to production
Understand AWS Copilot Pipeline architecture
mainlineAn AWS Copilot Pipeline automates the build and deployment process using AWS CodePipeline. It consists of three main stages:
- Source Stage: Triggers the pipeline when code is pushed to a configured GitHub, Bitbucket, or AWS CodeCommit repository.
- Build Stage: Downloads code from the repository, builds the container image for the Service, and pushes it to the Amazon ECR repositories for all Environments. It also uploads input files (such as Addon templates, Lambda function zip files, and environment variable files) to Amazon S3.
- Deploy Stages: Deploys the built artifacts to one or more Environments. You can optionally include manual approval steps for actions or test commands before or after deployment.
Note: Because the Build Stage uses Linux-based AWS CodeBuild, Copilot Pipelines currently do not support building Windows-based containers.
Understand AWS Copilot core concepts
mainlineAWS Copilot organizes containerized applications using a hierarchy of concepts: Application, Environment, Service, Job, and Pipeline. Understanding these relationships is essential for managing deployments across different stages (like testing and production).
Core Concepts Hierarchy
- Application: The highest-level container. It encompasses all related Services and Environments. An Application name represents your high-level product (e.g.,
chat). - Environment: An isolated deployment target (e.g.,
testorproduction). Each Environment contains its own shared resources, such as a VPC (subnets, security groups), ECS Cluster, and Load Balancer. Services deployed within the same Environment share these resources. - Service: Represents your code and the required infrastructure. When setting up a Service, you choose a "type" which determines the infrastructure (e.g., an internet-facing service uses an Application Load Balancer and AWS Fargate). Copilot uses a Manifest file to manage Service configurations like CPU, memory, and desired task count.
- Job: Represents ephemeral Amazon ECS tasks that are triggered by events. Once the task completes its work, it is deleted. Like Services, Jobs can be configured via a Manifest file.
- Pipeline: Automates the deployment process. When you push code to a supported Git repository (GitHub, BitBucket, or CodeCommit), the Pipeline automatically builds the Service, pushes the image to ECR, and deploys it to the specified Environment.
- Application: The highest-level container. It encompasses all related Services and Environments. An Application name represents your high-level product (e.g.,
Understand Scheduled Job resources
mainlineA Scheduled Job in Copilot is composed of several AWS resources managed via CloudFormation:
- Amazon ECS Task Definition
- Task Role
- Task Execution Role
- AWS Step Function State Machine (used for retrying on failures)
- Amazon EventBridge Event Rule (used to trigger the state machine)
Understand AWS Copilot CLI command grammar
mainlineAWS Copilot CLI uses a consistent "noun verb" or "verb" command structure. Commands are lowercase and do not use hyphens, colons, or underscores. Command nesting is limited to a single level; if you need to perform an action on a sub-resource, use flags instead of deeper nesting.
Common patterns include:
- Showing a resource:
copilot [entity] show [identifier] [options] - Listing resources:
copilot [entity] ls [options] - Creating a resource:
copilot [entity] init [identifier] [options] - Updating a resource:
copilot [entity] update [options] - Deleting a resource:
copilot [entity] delete [identifier...] [options]
- Showing a resource:
Understand the AWS Copilot CLI manifest
mainlineThe AWS Copilot CLI manifest is an infrastructure-as-code representation of a service, job, pipeline, or environment's architecture. It is generated during initialization commands (such as
copilot init,copilot svc init,copilot job init,copilot pipeline init, orcopilot env init) and is subsequently converted into an AWS CloudFormation template by Copilot.Using a manifest allows you to define high-level architectural settings rather than managing individual AWS resources manually.
Configure 'Load Balanced Web Service' manifest properties
mainlineA'Load Balanced Web Service'is an internet-facing service orchestrated by Amazon ECS on AWS Fargate. The manifest defines how the service is built, scaled, and exposed via an Application Load Balancer (ALB) or Network Load Balancer (NLB).Understand application-wide infrastructure (ECR and Release resources)
mainlineCopilot provisions several application-wide resources that support multi-region and multi-account deployments:
ECR Repositories
Each service in your application gets its own ECR Repository per region. These repositories live in the application account (not the environment accounts) and have policies allowing environment accounts to pull images. This setup maintains region isolation and reduces cross-region data transfer costs.
Release Infrastructure
For every region in your app, Copilot creates a KMS Key and an S3 bucket. These are used by CodePipeline to enable cross-region and cross-account deployments. All pipelines in your application share these resources. Policies are configured to allow environments (even in other accounts) to read encrypted deployment artifacts.
Quickstart: Deploy a sample application with copilot init
mainlineBefore starting, ensure you have the AWS CLI installed and configured via
aws configure.You can deploy a sample application to AWS App Runner or Amazon ECS on AWS Fargate using the
copilot initcommand. This command automates the creation of a VPC, Application Load Balancer, and an Amazon ECS Service.Follow these steps to run a sample service:
- Clone the sample repository.
- Navigate to the directory.
- Run
copilot initwith the required flags.
git clone git@github.com:aws-samples/aws-copilot-sample-service.git demo-app cd demo-app copilot init --app demo \ --name api \ --type 'Load Balanced Web Service' \ --dockerfile './Dockerfile' \ --deployTest Task Definition override rules
mainlineTo verify that your
taskdef_overridesare being applied correctly to the generated CloudFormation template, run the following commands to preview the output:copilot svc package # OR copilot job packagecopilot svc packageUse shell environment variables in Manifest files
mainlineYou can pass values to your Copilot Manifest by using shell environment variables with the
${VARIABLE_NAME}syntax.Copilot supports substituting variables in:
Stringfields (e.g.,image.location)Array of Stringsfields (e.g.,security_groups)Mapfields where the value type isStringorArray of Strings(e.g.,secrets).
Example: String substitution If your shell has
TAG=version01:image: location: id.dkr.ecr.zone.amazonaws.com/project-name:${TAG}It is interpreted as:
image: location: id.dkr.ecr.zone.amazonaws.com/project-name:version01Example: Array of Strings substitution If your shell has
SECURITY_GROUPS=["sg-123","sg-456"]:network: vpc: security_groups: ${SECURITY_GROUPS}It is interpreted as:
network: vpc: security_groups: - sg-123 - sg-456