Copilot

The AWS Copilot command line interface (CLI) commands simplify: building, releasing, and operating production-ready containerized applications on Amazon ECS from a local development environment. The AWS Copilot CLI aligns with developer workflows that support modern application best practices: from using infrastructure as code to creating a CI/CD pipeline provisioned on behalf of a user.

Setup: Step-by-Step Instructions

Prerequisite: Install and run Docker

Source: SETUP > Dev Environment > Docker

Validate: using basic example

The very basic tutorial to validate the setup and demonstrate basic capabilities. Source: Getting started with Amazon ECS using AWS Copilot Alternative basic example - Source: Deploy your first application

  • Confirm copilot setup

$ copilot --help
  • Clone the source code

$ cd <project-folder>
$ git clone https://github.com/aws-samples/amazon-ecs-cli-sample-app.git demo-app
$ cd demo-app
  • Initiate copilot project

$ cd demo-app
$ copilot init --app demo                      \
    --name api                                 \
    --type 'Load Balanced Web Service'         \
    --dockerfile './Dockerfile'                \
    --port 80                                  \
    --deploy

Welcome to the Copilot CLI! We're going to walk you through some questions
to help you get set up with a containerized application on AWS. An application is a collection of
containerized services that operate together.

Application name: demo
Workload type: Load Balanced Web Service
Service name: api
Manifest file for service api already exists. Skipping configuration.
Ok great, we'll set up a Load Balanced Web Service named api in application demo.

✔ Proposing infrastructure changes for stack demo-infrastructure-roles
- Creating the infrastructure for stack demo-infrastructure-roles                               [create complete]  [61.4s]
  - A StackSet admin role assumed by CloudFormation to manage regional stacks                   [create complete]  [25.5s]
  - An IAM role assumed by the admin role to create ECR repositories, KMS keys, and S3 buckets  [create complete]  [25.7s]
✔ The directory copilot will hold service manifests for application demo.

✔ Manifest file for service api already exists at copilot/api/manifest.yml, skipping writing it.
Your manifest contains configurations like your container size and port.

- Update regional resources with stack set "demo-infrastructure"  [succeeded]  [0.0s]
All right, you're all set for local development.
Deploy: Yes

✔ Manifest file for environment test already exists at copilot/environments/test/manifest.yml, skipping writing it.
- Update regional resources with stack set "demo-infrastructure"  [succeeded]  [0.0s]
- Update regional resources with stack set "demo-infrastructure"  [succeeded]        [134.2s]
  - Update resources in region "us-west-2"                        [create complete]  [128.2s]
    - KMS key to encrypt pipeline artifacts between stages        [create complete]  [124.7s]
    - ECR container image repository for "api"                    [create complete]  [0.0s]
    - S3 Bucket to store local artifacts                          [create complete]  [2.3s]
✔ Proposing infrastructure changes for the demo-test environment.
- Creating the infrastructure for the demo-test environment.  [create complete]  [58.0s]
  - An IAM Role for AWS CloudFormation to manage resources    [create complete]  [24.3s]
  - An IAM Role to describe resources in your environment     [create complete]  [23.6s]
✔ Provisioned bootstrap resources for environment test in region us-west-2 under application demo.
✔ Provisioned bootstrap resources for environment test.
✔ Proposing infrastructure changes for the demo-test environment.
- Creating the infrastructure for the demo-test environment.                  [update complete]  [80.8s]
  - An ECS cluster to group your services                                     [create complete]  [11.6s]
  - A security group to allow your containers to talk to each other           [create complete]  [0.0s]
  - An Internet Gateway to connect to the public internet                     [create complete]  [13.1s]
  - Private subnet 1 for resources with no internet access                    [create complete]  [3.1s]
  - Private subnet 2 for resources with no internet access                    [create complete]  [3.1s]
  - A custom route table that directs network traffic for the public subnets  [create complete]  [11.4s]
  - Public subnet 1 for resources that can access the internet                [create complete]  [5.6s]
  - Public subnet 2 for resources that can access the internet                [create complete]  [3.1s]
  - A private DNS namespace for discovering services within the environment   [create complete]  [48.7s]
  - A Virtual Private Cloud to control networking of your AWS resources       [create complete]  [11.9s]
Sending build context to Docker daemon  92.67kB
Step 1/2 : FROM nginx
latest: Pulling from library/nginx
7a6db449b51b: Pull complete 
ca1981974b58: Pull complete 
d4019c921e20: Pull complete 
7cb804d746d4: Pull complete 
e7a561826262: Pull complete 
7247f6e5c182: Pull complete 
Digest: sha256:b95a99feebf7797479e0c5eb5ec0bdfa5d9f504bc94da550c2f58e839ea6914f
Status: Downloaded newer image for nginx:latest
 ---> 2b7d6430f78d
Step 2/2 : COPY index.html /usr/share/nginx/html
 ---> c219c0e2f9d8
Successfully built c219c0e2f9d8
Successfully tagged 349327579537.dkr.ecr.us-west-2.amazonaws.com/demo/api:latest
WARNING! Your password will be stored unencrypted in /home/gabe/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
Using default tag: latest
The push refers to repository [349327579537.dkr.ecr.us-west-2.amazonaws.com/demo/api]
1fffd67c979f: Pushed 
73993eeb8aa2: Pushed 
2c31eef17db8: Pushed 
7b9055fc8058: Pushed 
04ab349b7b3b: Pushed 
226117031573: Pushed 
6485bed63627: Pushed 
latest: digest: sha256:c6575be1f76867bf4442dff3094a3818adfb6c43ec92326a3ac4be28aef40bd3 size: 1778
✔ Proposing infrastructure changes for stack demo-test-api
- Creating the infrastructure for stack demo-test-api                             [create complete]  [261.8s]
  - Service discovery for your services to communicate within the VPC             [create complete]  [4.7s]
  - Update your environment's shared resources                                    [update complete]  [118.8s]
    - A security group for your load balancer allowing HTTP traffic               [create complete]  [5.8s]
    - An Application Load Balancer to distribute public traffic to your services  [create complete]  [92.2s]
    - A load balancer listener to route HTTP traffic                              [create complete]  [1.2s]
  - An IAM role to update your environment stack                                  [create complete]  [25.1s]
  - An IAM Role for the Fargate agent to make AWS API calls on your behalf        [create complete]  [25.1s]
  - A HTTP listener rule for forwarding HTTP traffic                              [create complete]  [3.3s]
  - A custom resource assigning priority for HTTP listener rules                  [create complete]  [3.0s]
  - A CloudWatch log group to hold your service logs                              [create complete]  [0.0s]
  - An IAM Role to describe load balancer rules for assigning a priority          [create complete]  [25.1s]
  - An ECS service to run and maintain your tasks in the environment cluster      [create complete]  [78.6s]
    Deployments                                                                                       
               Revision  Rollout      Desired  Running  Failed  Pending                                       
      PRIMARY  1         [completed]  1        1        0       0                                             
  - A target group to connect the load balancer to your service                   [create complete]  [0.0s]
  - An ECS task definition to group your containers and run them on ECS           [create complete]  [0.0s]
  - An IAM role to control permissions for the containers in your tasks           [create complete]  [25.1s]
✔ Deployed service api.
Recommended follow-up action:
  - You can access your service at http://demo-Publi-YXBXFJW6X0SM-1515999460.us-west-2.elb.amazonaws.com over the internet.
- Be a part of the Copilot ✨community✨!
  Ask or answer a question, submit a feature request...
  Visit 👉 https://aws.github.io/copilot-cli/community/get-involved/ to see how!
$
  • Copilot commands

$ copilot app ls
demo

$ copilot app show
About

  Name     demo
  Version  v1.0.2 
  URI      

Environments

  Name    AccountID     Region
  ----    ---------     ------
  test    349327579537  us-west-2

Workloads

  Name    Type                       Environments
  ----    ----                       ------------
  api     Load Balanced Web Service  test

Pipelines

  Name
  ----

$ copilot env ls
test

$ copilot svc show
Only found one service, defaulting to: api
About

  Application  demo
  Name         api
  Type         Load Balanced Web Service

Configurations

  Environment  Tasks     CPU (vCPU)  Memory (MiB)  Platform      Port
  -----------  -----     ----------  ------------  --------      ----
  test         1         0.25        512           LINUX/X86_64  80

Routes

  Environment  URL
  -----------  ---
  test         http://demo-Publi-YXBXFJW6X0SM-1515999460.us-west-2.elb.amazonaws.com

Service Discovery

  Environment  Namespace
  -----------  ---------
  test         api.test.demo.local:80

Variables

  Name                                Container  Environment  Value
  ----                                ---------  -----------  -----
  COPILOT_APPLICATION_NAME            api        test         demo
  COPILOT_ENVIRONMENT_NAME              "          "          test
  COPILOT_LB_DNS                        "          "          demo-Publi-YXBXFJW6X0SM-1515999460.us-west-2.elb.amazonaws.com
  COPILOT_SERVICE_DISCOVERY_ENDPOINT    "          "          test.demo.local
  COPILOT_SERVICE_NAME                  "          "          api

$  copilot svc ls
Name                Type
----                ----
api                 Load Balanced Web Service

$ copilot svc logs
Found only one deployed service api in environment test
copilot/api/022925ab14fd4 10.0.1.93 - - [07/Sep/2022:22:34:41 +0000] "GET / HTTP/1.1" 200 3165 "-" "ELB-HealthChecker/2.0" "-"
copilot/api/022925ab14fd4 10.0.0.163 - - [07/Sep/2022:22:34:51 +0000] "GET / HTTP/1.1" 200 3165 "-" "ELB-HealthChecker/2.0" "-"
copilot/api/022925ab14fd4 10.0.1.93 - - [07/Sep/2022:22:35:11 +0000] "GET / HTTP/1.1" 200 3165 "-" "ELB-HealthChecker/2.0" "-"
copilot/api/022925ab14fd4 10.0.0.163 - - [07/Sep/2022:22:35:21 +0000] "GET / HTTP/1.1" 200 3165 "-" "ELB-HealthChecker/2.0" "-"
copilot/api/022925ab14fd4 10.0.1.93 - - [07/Sep/2022:22:35:41 +0000] "GET / HTTP/1.1" 200 3165 "-" "ELB-HealthChecker/2.0" "-"
copilot/api/022925ab14fd4 10.0.0.163 - - [07/Sep/2022:22:35:51 +0000] "GET / HTTP/1.1" 200 3165 "-" "ELB-HealthChecker/2.0" "-"
copilot/api/022925ab14fd4 10.0.1.93 - - [07/Sep/2022:22:36:11 +0000] "GET / HTTP/1.1" 200 3165 "-" "ELB-HealthChecker/2.0" "-"
copilot/api/022925ab14fd4 10.0.0.163 - - [07/Sep/2022:22:36:21 +0000] "GET / HTTP/1.1" 200 3165 "-" "ELB-HealthChecker/2.0" "-"
copilot/api/022925ab14fd4 10.0.1.93 - - [07/Sep/2022:22:36:41 +0000] "GET / HTTP/1.1" 200 3165 "-" "ELB-HealthChecker/2.0" "-"
copilot/api/022925ab14fd4 10.0.0.163 - - [07/Sep/2022:22:36:51 +0000] "GET / HTTP/1.1" 200 3165 "-" "ELB-HealthChecker/2.0" "-"

$ copilot svc status
Found only one deployed service api in environment test
Task Summary

  Running   ██████████  1/1 desired tasks are running
  Health    ██████████  1/1 passes HTTP health checks

Tasks

  ID        Status      Revision    Started At   HTTP Health
  --        ------      --------    ----------   -----------
  022925ab  RUNNING     1           3 hours ago  HEALTHY

$ 

To be filed...

[Source: AWS Copilot CLI]

Overview of Copilot and concept.

AWS Workshop - INTRODUCTION TO ECS (ELASTIC CONTAINER SERVICE)

References

Last updated