本日も乙

ただの自己満足な備忘録。

AWS Copilot をひと通り使ってみた

Amazon ECS のデプロイツールを調査した際に AWS Copilot をひと通り触ってみたのでそのメモです。

AWS Copilot とは

Amazon ECS を簡単にデプロイツールで ECS CLI の後継です。2020年11月に GA になりました。

AWS Copilot のメリットは Dockerfile とソースコードさえあれば、1から環境構築含めて簡単に Amazon ECS のサービスを立ち上げることができます。また、Step Functions との連携による定期バッチ処理や Code Pipeline による CI/CD 環境も Copilot CLI によって一撃で作ることができます。

Getting started

まずはドキュメントにあるサンプルコードを動かすところから始めてみます。Deploy your first application - AWS Copilot CLI を見ながらやってみました。

実行環境は以下です。

  • WSL2(Ubuntu 20.04 LTS)
  • Copilot CLI v1.0.0
  • AWS CLI aws-cli/2.1.4 Python/3.7.3 Linux/4.19.128-microsoft-standard exe/x86_64.ubuntu.20
  • Docker 20.10.0

AWS Copilot を使うためには AWS CLI、Docker が必要なので事前にインストールしておいてください。また、aws configure で初期設定します。必要に応じて AWS アクセスキーを入れてください。

$ aws configure
AWS Access Key ID [None]: 
AWS Secret Access Key [None]: 
Default region name [None]: ap-northeast-1
Default output format [None]:

別プロファイルを使う場合は環境変数 AWS_PROFILE に入れる
$ export AWS_PROFILE=xxxxxx

Copilot CLI をインストールします。

$ sudo su -
$ curl -Lo /usr/local/bin/copilot https://github.com/aws/copilot-cli/releases/latest/download/copilot-linux && chmod +x /usr/local/bin/copilot && copilot --version
copilot version: v1.0.0
$ exit

サンプルコードを持ってきます。

# サンプルコード
$ git clone https://github.com/aws-samples/aws-copilot-sample-service example
$ cd example

copilot init を実行してインタラクティブに値を入れると VPC の構築から ECS のデプロイまで一気にやってくれます。

copilot init がやっていること

  1. CloudFormationでVPCなどを作成
  2. ローカルでDocker Build
  3. ECRにPush
$ copilot init
Welcome to the Copilot CLI! We're going to walk you through some questions
to help you get set up with an application on ECS. An application is a collection of
containerized services that operate together.

Application name: example-app
Workload type: Load Balanced Web Service
Service name: front-end
Dockerfile: ./Dockerfile
Ok great, we'll set up a Load Balanced Web Service named front-end in application example-app listening on port 80.

✔ Created the infrastructure to manage services and jobs under application example-app.

✔ Wrote the manifest for service front-end at copilot/front-end/manifest.yml
Your manifest contains configurations like your container size and port (:80).

✔ Created ECR repositories for service front-end.

All right, you're all set for local development.
Deploy: Yes

✔ Created the infrastructure for the test environment.
- Virtual private cloud on 2 availability zones to hold your services and jobs     [Complete]
  - Internet gateway to connect the network to the internet                        [Complete]
  - Public subnets for internet facing services and jobs                           [Complete]
  - Private subnets for services and jobs that can't be reached from the internet  [Complete]
  - Routing tables for services and jobs to talk with each other                   [Complete]
- ECS Cluster to hold your services and jobs                                       [Complete]
✔ Linked account 123456789012 and region ap-northeast-1 to application example-app.

✔ Created environment test in region ap-northeast-1 under application example-app.
Environment test is already on the latest version v1.1.0, skip upgrade.
[+] Building 11.4s (7/7) FINISHED
...(省略)...
✔ Deployed front-end, you can access it at http://examp-Publi-ABCDEFGHIJKLN-1234567890.ap-northeast-1.elb.amazonaws.com.

you can access it at http://examp-Publi... で表示されている URL をブラウザから確認してページが表示されていれば完了です。

実行後、マニフェストファイルが作成されていました。

./copilot
└── front-end
    └── manifest.yml

使い終わったら copilot app delete ですべて削除できます。

$ copilot app delete

コンセプト

Application

関連サービスやパイプラインなどをグルーピングしたものです。ECSクラスタが概念的に近いです。

Environments

複数の環境を作成することができ、それぞれ AWS リソースを VPC レベルで分離することができます(同じ VPC に含めることもできます)。copilot init を実行すると、デフォルトで test 環境が作られます。

Service

ECS サービスが概念的に近いです。Service には2種類あります。

Jobs

ECS タスク。Scheduled Job のみサポートされています。

Pipelines

AWS CodePipeline によるデプロイパイプライン。copilot deploy でもデプロイできますが、途中で承認を挟むなどリリースプロセスを柔軟にしたい場合にはパイプラインが便利です。

Manifest

CloudFormation テンプレートに変換される設定ファイル。

Advanced

ざっと使えるようになったところでもう少しだけ突っ込んで使ってみます。

ドメインの設定

私が所有しているサブドメイン copilot.jicoman.info でアプリケーションを作成します。

$ copilot app init --domain copilot.jicoman.info
Note: Looks like you're creating an application using credentials set by environment variables.
Copilot will store your application metadata in this account.
We recommend using credentials from named profiles. To learn more:
https://aws.github.io/copilot-cli/docs/credentials/

Use existing application: No  # No にすると新しいApplicationを作成できる
Application name: hoge-app    # 新しいApplication
✔ Created the infrastructure to manage services and jobs under application hoge-app.

✔ The directory copilot will hold service manifests for application hoge-app.

Recommended follow-up actions:
- Run `copilot init` to add a new service or job to your application.

実行後 hoge-app.copilot.jicoman.info の Route53 ホストゾーンが作成されていました。

既存の VPC、サブネットをインポートする

すでにVPC、サブネットが作成されていたら --import-vpc-id--import-public-subnets--import-private-subnets でインポートすることができます。ステージング用の Environment を作成します。

$ copilot env init --name stg --region ap-northeast-1 \
--import-vpc-id vpc-0123456789abcdefg \
--import-public-subnets subnet-example0123456789,subnet-example1234567890 \
--import-private-subnets subnet-exampleabcdefghij,subnet-exampleklmnopqrst

Which credentials would you like to use to create stg? Enter temporary credentials
What's your AWS Access Key ID?
What's your AWS Secret Access Key?
What's your AWS Session Token?
⠏ Creating the infrastructure for the stg environment.
- ECS Cluster to hold your services and jobs  [Complete]
✔ Linked account 123456789012 and region ap-northeast-1 to application hoge-app.

✔ Created environment stg in region ap-northeast-1 under application hoge-app.

Copilot v1.0.0 の時点では --import-private-subnets でプライベートサブネットを指定しても Fargate のコンテナはすべてパブリックサブネットに作成されます。Issue に上がっていますがプライベートサブネットの場合、インターネットに通信するために NAT Gateway が必要でありコストがかかるからパブリックサブネットに置くようにしているとのことです。改善される見込みはありそうなので期待したいところです。

Load Balanced Webservice - must provide an option to deploy service in private subnets and bind it with public ALB sitting in public subnet · Issue #1489 · aws/copilot-cli

サービスの作成

copilot svc init を実行するとマニフェストファイル(copilot/front-end/manifest.yml)と空の ECR リポジトリ(hoge-app/front-end)が作成されます。

$ copilot svc init --name front-end \
--dockerfile ./Dockerfile \
--svc-type "Load Balanced Web Service"

Note: It's best to run this command in the root of your workspace.
✔ Wrote the manifest for service front-end at copilot/front-end/manifest.yml
Your manifest contains configurations like your container size and port (:80).

✔ Created ECR repositories for service front-end.

Recommended follow-up actions:
- Update your manifest copilot/front-end/manifest.yml to change the defaults.
- Run `copilot svc deploy --name front-end --env test` to deploy your service to a test environment.

デプロイ

copilot svc deploy を実行すると以下のことを行ってデプロイされます。

  1. Dockerfile から Docker イメージをローカル環境でビルド
  2. Git コミットのハッシュ値で Docker イメージにタグ付け
  3. Docker イメージを ECR にプッシュ
  4. マニフェストファイルを元に CloudFormation テンプレートを作成、適用
  5. ECS タスクの作成・更新
$ $ copilot svc deploy --name front-end --env stg

Environment stg is already on the latest version v1.1.0, skip upgrade.
...(省略)...
✔ Deployed front-end, you can access it at https://front-end.stg.hoge-app.copilot.jicoman.info.

最初にやった Getting Started とは異なり、カスタムドメインでアクセスすることができます。

本番環境の作成

--prod オプションをつけると本番環境として扱うことができます。具体的に何が違うのかは詳しいことを追えていません。。。

$ copilot env init --name prod --region ap-northeast-1 --prod \
--import-vpc-id vpc-0123456789abcdefg \
--import-public-subnets subnet-example0123456789,subnet-example1234567890 \
--import-private-subnets subnet-exampleabcdefghij,subnet-exampleklmnopqrst

同一の VPC で複数の Environment を設定することはできないみたいです。

The VPC vpc-0123456789abcdefg in region ap-northeast-1 has already been associated with the hosted zone Z0194799NX5LWYHOGE01 with the same domain name. (Service: AmazonRoute53; Status Code: 400; Error Code: ConflictingDomainExists; Request ID: 1551cd27-2202-4bbe-8e9a-034a465006cf; Proxy: null)

今回は新規で VPC とサブネットを作成します。--override-xxxx で VPC、サブネットの CIDR を指定できます。

$ copilot env init --name prod --region ap-northeast-1 --prod \
--override-vpc-cidr 10.1.0.0/16 \
--override-public-cidrs 10.1.0.0/24,10.1.1.0/24 \
--override-private-cidrs 10.1.2.0/24,10.1.3.0/24

デプロイすれば完了です。

$ copilot svc deploy --name front-end --env prod
Environment prod is already on the latest version v1.1.0, skip upgrade.
...(省略)...
✔ Deployed front-end, you can access it at https://front-end.prod.hoge-app.copilot.jicoman.info.

デプロイしたらリソース状況を確認しましょう。

$ copilot svc show --app hoge-app --name front-end
About

  Application       hoge-app
  Name              front-end
  Type              Load Balanced Web Service

Configurations

  Environment  Tasks   CPU (vCPU)  Memory (MiB)  Port
  prod         1       0.25        512           80
  stg          1       0.25        512           80

Routes

  Environment  URL
  prod         https://front-end.prod.hoge-app.copilot.jicoman.info
  stg          https://front-end.stg.hoge-app.copilot.jicoman.info

Service Discovery

  Environment       Namespace
  prod, stg         front-end.hoge-app.local:80

Variables

  Name                                Environment   Value
  COPILOT_APPLICATION_NAME            prod          hoge-app
  -                                   stg           -
  COPILOT_ENVIRONMENT_NAME            prod          prod
  -                                   stg           stg
  COPILOT_LB_DNS                      prod          hoge-Publi-ABCDEFGHIJKLN-1234567890.ap-northeast-1.elb.amazonaws.com
  -                                   stg           hoge-Publi-1234ABCDEFGHI-ABCD123456.ap-northeast-1.elb.amazonaws.com
  COPILOT_SERVICE_DISCOVERY_ENDPOINT  prod          hoge-app.local
  -                                   stg           -
  COPILOT_SERVICE_NAME                prod          front-end
  -                                   stg           -

パイプラインの作成

AWS Codepipeline によるデプロイパイプラインを作ります。Git Push を起点とするため、サンプルリポジトリを Fork しておいてください。また、GitHub アクセストークンが必要なので前もって発行しておきます。アクセストークンは repoadmin:repo_hook の権限が必要です。

$ git clone git@github.com:ohsawa0515/aws-copilot-sample-service.git
$ cd aws-copilot-sample-service

# 先ほど生成されたマニフェストファイルをもってくる
$ cp -a ~/example/copilot ./

# マニフェストファイルをコミットに含める
$ git add -A
$ git commit -a -m "add copilot manifest files"

copilot pipeline init でパイプラインのマニフェストファイルを生成します。

$ copilot pipeline init --environments "stg,prod"

Which GitHub repository would you like to use for your service? git@github.com:ohsawa0515/aws-copilot-sample-service
Please enter your GitHub Personal Access Token for your repository aws-copilot-sample-service:
✔ Created the secret github-token-hoge-app-aws-copilot-sample-service for pipeline source stage!
✔ Wrote the pipeline manifest for aws-copilot-sample-service at 'copilot/pipeline.yml'
The manifest contains configurations for your CodePipeline resources, such as your pipeline stages and build steps.
✔ Wrote the buildspec for the pipeline's build stage at 'copilot/buildspec.yml'
The buildspec contains the commands to build and push your container images to your ECR repositories.

Recommended follow-up actions:
- Commit and push the generated buildspec and manifest file.
- Update the build phase of your buildspec to unit test your services before pushing the images.
- Update your pipeline manifest to add additional stages.
- Run `copilot pipeline update` to deploy your pipeline for the repository.

GitHub アクセストークンは Secret Manager に保存されています。copilot ディレクトリ以下に buildspec.ymlpipeline.yml が作成されていました。copilot pipeline update で生成したマニフェストファイルを元にパイプラインを作成します。CloudFormation を通して AWS CodePipeline と CodeBuild が作成されます。

$ copilot pipeline update

✔ Successfully added pipeline resources to your application: hoge-app
✔ Successfully created a new pipeline: pipeline-hoge-app-ohsawa0515-aws-copilot-sample-service

マネジメントコンソールで CodePipeline によるデプロイパイプラインを確認できます。

Copilot CLI からも確認できます。

$ copilot pipeline show --app hoge-app
About

  Name              pipeline-hoge-app-ohsawa0515-aws-copilot-sample-service
  Region            ap-northeast-1
  AccountID         xxxxxxxxxxxxll
  Created At        3 minutes ago
  Updated At        3 minutes ago

Stages

  Name              Category            Provider            Details
  ----              ----                ----                ----
  Source            Source              GitHub              Repository: ohsawa0515/aws-copilot-sample-service
  Build             Build               CodeBuild           BuildProject: pipeline-hoge-app-ohsawa0515-aws-copilot-sample-service-BuildProject
  DeployTo-stg      Deploy              CloudFormation      StackName: hoge-app-stg-front-end
  DeployTo-prod     Approval            Manual

パイプラインの流れは以下のようになっています。

  1. GitHub への Push を起点にパイプライン開始
  2. CodeBuild で Docker イメージのビルド、ECR へのプッシュ
  3. CloudFormation でステージング環境へのデプロイ
  4. 手動承認を経て、CloudFormatin で本番環境へのデプロイ

パイプラインによるデプロイをしてみます。試しに適当はファイルを編集します。

# 変更を加えてコミット
$ git diff
diff --git a/index.html b/index.html
index 2e1cd33..4274036 100644
--- a/index.html
+++ b/index.html
@@ -7,6 +7,7 @@
     <title>AWS Copilot CLI</title>
 </head>
 <body style="background-color:rgb(35, 47, 62);">
+    <h1>Deploy!!</h1>

$ git commit -a -m "add h1 tag"
$ git push origin # PushするとCodePipelineが実行される

バックエンドサービスの作成

先ほどのサービス作成時に --svc-type オプションで Load Balanced Web Service を指定したので、本節では Backend Service を指定してバックエンドサービスを作成します。

$ copilot svc init --name back-end \
--dockerfile ./Dockerfile \
--svc-type "Backend Service"

Note: It's best to run this command in the root of your workspace.
✔ Wrote the manifest for service back-end at copilot/back-end/manifest.yml
Your manifest contains configurations like your container size and port (:80).

✔ Created ECR repositories for service back-end.

Recommended follow-up actions:
- Update your manifest copilot/back-end/manifest.yml to change the defaults.
- Run `copilot svc deploy --name back-end --env test` to deploy your service to a test environment.

$ git add copilot/back-end/manifest.yml
$ git commit -m "add backend manifest"

デプロイ

$ copilot svc deploy --name back-end --env stg

# 確認
$ copilot svc show --app hoge-app --name back-end
About

  Application       hoge-app
  Name              back-end
  Type              Backend Service

Configurations

  Environment       Tasks               CPU (vCPU)          Memory (MiB)        Port
  stg               1                   0.25                512                 80

Service Discovery

  Environment       Namespace
  stg               back-end.hoge-app.local:80

Variables

  Name                                Environment         Value
  COPILOT_APPLICATION_NAME            stg                 hoge-app
  COPILOT_ENVIRONMENT_NAME            stg                 stg
  COPILOT_SERVICE_DISCOVERY_ENDPOINT  stg                 hoge-app.local
  COPILOT_SERVICE_NAME                stg                 back-end

接続確認

外部からアクセスできないため、VPC 内に EC2 インスタンスを立てて確認します。

# サービスディスカバリの名前解決ができている
$ dig back-end.hoge-app.local

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-9.P2.amzn2.0.4 <<>> back-end.hoge-app.local
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 54510
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;back-end.hoge-app.local.       IN      A

;; ANSWER SECTION:
back-end.hoge-app.local. 10     IN      A       10.0.1.206

;; Query time: 1 msec
;; SERVER: 10.0.0.2#53(10.0.0.2)
;; WHEN: Thu Dec 17 14:13:42 UTC 2020
;; MSG SIZE  rcvd: 68

# 疎通可能
$ curl --head back-end.hoge-app.local
HTTP/1.1 200 OK
Server: nginx/1.19.6
Date: Thu, 17 Dec 2020 14:15:13 GMT
Content-Type: text/html
Content-Length: 3195
Last-Modified: Thu, 17 Dec 2020 12:24:13 GMT
Connection: keep-alive
ETag: "5fdb4ded-c7b"
Accept-Ranges: bytes

タスク数を2に増やしてデプロイすると、2つのタスクのプライベートIPアドレスが返ってくるのが確認できます。

$ git diff
diff --git a/copilot/back-end/manifest.yml b/copilot/back-end/manifest.yml
index 00aed02..1c5b8dc 100644
--- a/copilot/back-end/manifest.yml
+++ b/copilot/back-end/manifest.yml
@@ -19,7 +19,7 @@ cpu: 256
 # Amount of memory in MiB used by the task.
 memory: 512
 # Number of tasks that should be running in your service.
-count: 1
+count: 2

# デプロイ
$ copilot svc deploy --name back-end --env stg

$ dig back-end.hoge-app.local

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-9.P2.amzn2.0.4 <<>> back-end.hoge-app.local
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32704
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
back-end.hoge-app.local. 10     IN      A       10.0.1.252
back-end.hoge-app.local. 10     IN      A       10.0.0.211

;; Query time: 1 msec
;; SERVER: 10.0.0.2#53(10.0.0.2)
;; WHEN: Thu Dec 17 14:21:45 UTC 2020
;; MSG SIZE  rcvd: 84

copilot pipeline update でバックエンドサービスもパイプラインに組み込むことができます。

$ copilot pipeline update

✔ Successfully added pipeline resources to your application: hoge-app
Are you sure you want to update an existing pipeline: pipeline-hoge-app-ohsawa0515-aws-copilot-sample-service? Yes
✔ Successfully updated pipeline: pipeline-hoge-app-ohsawa0515-aws-copilot-sample-service

データソースの追加

S3 と DynamoDB がデフォルトでサポートされています。

# S3の場合
$ copilot storage init --name hoge-bucket --storage-type S3 --workload front-end

✔ Wrote CloudFormation template for S3 Bucket hoge-bucket at copilot/front-end/addons/hoge-bucket.yml

Recommended follow-up actions:
- Update front-end's code to leverage the injected environment variable `HOGEBUCKET_NAME`
- Run `copilot deploy --name front-end` to deploy your storage resources.

front-end 以下に addons/hoge-bucket.yml が作成されていますた。このファイルの中身は CloudFormation テンプレートになっていて S3 バケット、S3 バケットポリシー、IAM ポリシーが定義されています。

./copilot
├── back-end
│   └── manifest.yml
├── buildspec.yml
├── front-end
│   ├── addons
│   │   └── hoge-bucket.yml
│   └── manifest.yml
└── pipeline.yml

デプロイして CloudFormation テンプレートが適用されると S3 バケットが作成されます。

$ copilot svc deploy --name front-end --env stg

# S3バケットが作成されたことの確認
$ aws s3 ls
2020-12-18 00:12:54 hoge-app-stg-front-end-hoge-bucket

アドオン

S3、DynamoDB 以外のデータソースを扱いたい場合や、ECS タスクから AWS リソースにアクセスする場合はアドオンとして任意の CloudFormation テンプレートを組み込むことができます。今回は EC2 の参照権限のみを付与した IAM ポリシーを作成します。デプロイすると CloudFormation のスタックが作成・実行され、ECS タスクロールに IAM ポリシーが追加されます。

$ cat copilot/front-end/addons/readonly-ec2.yml
Parameters:
  App:
    Type: String
    Description: Your application's name.
  Env:
    Type: String
    Description: The environment name your service, job, or workflow is being deployed to.
  Name:
    Type: String
    Description: The name of the service, job, or workflow being deployed.
Resources:
  EC2ReadOnlyAccessPolicy:
    Type: AWS::IAM::ManagedPolicy
    Properties:
      PolicyDocument:
        Version: 2012-10-17
        Statement:
          - Sid: EC2ReadOnly
            Effect: Allow
            Action:
              - ec2:Describe*
              - elasticloadbalancing:Describe*
              - autoscaling:Describe*
            Resource: "*"

Outputs:
  EC2ReadOnlyAccessPolicy:
    Description: "The IAM::ManagedPolicy to attach to the task role"
    Value: !Ref EC2ReadOnlyAccessPolicy

# デプロイ
$ copilot svc deploy --name front-end --env stg

単発の ECS タスクを実行

copilot task run で ECS タスクを実行できます。データベースマイグレーションなどを単体のコマンドを実行するのに便利です。

$ copilot task run --app hoge-app \
--env prod \
--follow \
--image alpine:latest \
--command "echo 'Howdy, Copilot'"

✔ Successfully provisioned task resources.

✔ Task aws-copilot-sample-service is running.

copilot-task/aws-copilot- Howdy Copilot
Task has stopped.

ECS タスクの定期実行

Jobs を設定することで ECS タスクを定期実行できます。定期実行には2種類あります。

  • Rate: 固定レート。「3時間毎」のように固定の時間間隔で定期実行する
  • Cron: クーロン。「月初の12時30分」のように柔軟に定期実行する
$ copilot job init --app hoge-app \
--name scheduled-job \
--dockerfile ./Dockerfile \
--schedule "*/5 * * * *"  # 5分間隔

✔ Wrote the manifest for job scheduled-job at copilot/scheduled-job/manifest.yml
Your manifest contains configurations like your container size and job schedule (*/5 * * * *).

✔ Created ECR repositories for job scheduled-job.

Recommended follow-up actions:
- Update your manifest copilot/scheduled-job/manifest.yml to change the defaults.
- Run `copilot job deploy --name scheduled-job --env test` to deploy your job to a test environment.

デプロイすると Step Functions のステートマシンが作成され、Event Bridge によって定期実行されます。

$ copilot job deploy --name scheduled-job --env stg

削除

使い終わったら削除します。

# Jobsの削除
$ copilot job deletecopilot job delete

Only found one job, defaulting to: scheduled-job
Are you sure you want to delete job scheduled-job from application hoge-app? Yes
✔ Deleted the stack of job scheduled-job from environment stg.
✔ Stopped running tasks of job scheduled-job from environment stg.
✔ Deleted the stack of job scheduled-job from environment prod.
✔ Deleted resources of job scheduled-job from application hoge-app.
✔ Deleted job scheduled-job from application hoge-app.
Recommended follow-up actions:
- Run `copilot pipeline update` to update the corresponding pipeline if it exists.

# パイプラインの削除
$ copilot pipeline delete

Are you sure you want to delete pipeline pipeline-hoge-app-ohsawa0515-aws-copilot-sample-service from application hoge-app? Yes
Are you sure you want to delete the source secret github-token-hoge-app-aws-copilot-sample-service associated with pipeline pipeline-hoge-app-ohsawa0515-aws-copilot-sample-service? Yes
✔ Deleted secret github-token-hoge-app-aws-copilot-sample-service.
✔ Deleted pipeline pipeline-hoge-app-ohsawa0515-aws-copilot-sample-service from application hoge-app.

# アプリなど諸々削除
$ copilot app delete

Are you sure you want to delete application hoge-app? Yes
✔ Deleted service back-end from environment stg.
✔ Deleted service back-end from environment prod.
✔ Deleted resources of service back-end from application hoge-app.
✔ Deleted service back-end from application hoge-app.
✔ Deleted service front-end from environment stg.
✔ Deleted service front-end from environment prod.
✔ Deleted resources of service front-end from application hoge-app.
✔ Deleted service front-end from application hoge-app.
✔ Deleted environment stg from application hoge-app.
✔ Deleted environment prod from application hoge-app.
✔ Cleaned up deployment resources.
✔ Deleted secret github-token-hoge-app-aws-copilot-sample-service.
✔ Deleted pipeline pipeline-hoge-app-ohsawa0515-aws-copilot-sample-service from application hoge-app.
✔ Deleted application resources.
✔ Deleted application configuration.
✔ Deleted local .workspace file.

長所

個人的に良かった点を挙げます。

  • アプリケーションのコードと Dockerfile さえあればコマンド一発で AWS 上に環境構築することができる
  • コマンドとマニフェストファイルで設定を変えることができて、開発者は AWS 上のリソースを意識しなくても利用できる
  • 複数 AWS アカウント、複数環境へのデプロイやパイプラインもサポートされている

短所

個人的に改善してほしい点を挙げます。

  • ALB、Fargate ともにパブリックサブネットにできてしまう。プライベートサブネットへの配置ができない
  • Blue/Green、カナリアデプロイがサポートされていない
  • アドオンによる CloudFormation で柔軟に設定できる分、CloudFormation 地獄になりそう
  • ECS タスクロールなど少しの変更でデプロイする場合でも Docker イメージのビルドを毎回するので時間がかかる

まとめ

AWS Copilot をひと通り触ってみて個人的に長所と短所をまとめてみました。細かい設定ができないもどかしさはありますが、作ったアプリを最速で公開することができるので、個人利用やデモを作るのに向いていると思いました。GA になったばかりで事例が少なく、"枯れていない"ため、本格稼働させるのにハードルが高いと思うのでプロダクション環境に載せるのは現時点ではなかなか勇気がいると思います。今後のアップデートと事例が増えてくることに期待したいですね。

参考URL