AWS Copilot CLI Documentation

repository·mainline·Indexed 25 days ago

https://github.com/aws/copilot-cli

A 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.

Tokens
144.8K
Snippets
487
Records
797
Agent score
86%

What's inside AWS Copilot CLI

  1. Overview of AWS Copilot CLI

    mainline
    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.
  2. Overview of AWS Copilot CLI capabilities

    mainline

    AWS 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
  3. Understand AWS Copilot Pipeline architecture

    mainline

    An AWS Copilot Pipeline automates the build and deployment process using AWS CodePipeline. It consists of three main stages:

    1. Source Stage: Triggers the pipeline when code is pushed to a configured GitHub, Bitbucket, or AWS CodeCommit repository.
    2. 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.
    3. 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.

  4. Understand AWS Copilot core concepts

    mainline

    AWS 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., test or production). 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.
  5. Understand AWS Copilot CLI command grammar

    mainline

    AWS 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]
  6. Understand the AWS Copilot CLI manifest

    mainline

    The 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, or copilot 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.

  7. Understand application-wide infrastructure (ECR and Release resources)

    mainline

    Copilot 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.

  8. Quickstart: Deploy a sample application with copilot init

    mainline

    Before 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 init command. This command automates the creation of a VPC, Application Load Balancer, and an Amazon ECS Service.

    Follow these steps to run a sample service:

    1. Clone the sample repository.
    2. Navigate to the directory.
    3. Run copilot init with 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'            \
      --deploy
  9. Use shell environment variables in Manifest files

    mainline

    You can pass values to your Copilot Manifest by using shell environment variables with the ${VARIABLE_NAME} syntax.

    Copilot supports substituting variables in:

    • String fields (e.g., image.location)
    • Array of Strings fields (e.g., security_groups)
    • Map fields where the value type is String or Array 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:version01

    Example: 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