LoginSignup
18
8

More than 1 year has passed since last update.

概要

  • 本記事では、AWS Copilot について何が嬉しいのか。実際に検証してみたという内容をお届けしようと思います。
  • AWS Copilot なにそれ美味しいの?という方を対象としております。

AWS Copilot とは

  • 2020/11 に GA されたのが AWS Copilot です。
  • AWS Copilot とは何かというと、Amazon ECS CLI の後継にあたるものです。
  • ECS CLI は、Amazon ECS 環境に対するコンテナデプロイのためのツールとなっています。
  • ただ、AWS Copilot がなぜ登場したのかいうと、より ECS (App Runnerへのデプロイも対応)でコンテナを実行したいとなった時のワークフローをシンプルにするためというモチベーションがあるようです。

だって大変じゃない、簡単なアプリケーション動かす時に色々考えるの、

  • 例えば、ECS 上でコンテナを実行しようと思った時に ECS を含めたアーキテクチャを考えて、その構成の中に各種コンポーネント(例えば、VPC や ALB、デプロイのためのパイプライン)も考慮しないといけません。
  • これ、大変ですよね。ちょっとしたコンテナで実行するアプリケーションを動かしたいだけなのに...
  • AWS Copilot では、このような面倒なことを解決してくれます。AWS Copilot を使う時、AWS Copilot が可用性を考慮した構成や LB の構築、設定などをいい感じにしてくれます。
  • また、コードリポジトリに Push する度、最新バージョンのアプリケーションを自動デプロイをするためのパイプラインも作ってくれます。

でもこのあたりは手が届かない。

  • 例えば、既存の ECS クラスターに対してを向き先にすることができない。また、ALB も同様。
  • コンテナが稼働するデータプレーンとして EC2 インスタンス を選択することができなかったりします。

AWS Copilot のコンセプト

  • AWS Copilot にはドキュメントに記載もあるようにコンセプトが存在する。

Application

  • Application とは、後述の Service と Environment を包括するような概念です。
  • 例を挙げるならば、test-ui, test-api という2つの Service を持つ Test-app という名前の Application のようなイメージとなります。

Environment

  • Environment ではそれぞれ異なるバージョンのサービスを実行できる環境を用意できるので、テスト環境や本番環境といったものを作ることができます。

Service

  • Service とは、ECS におけるサービスと同じで、docker イメージを起動する単位となります。
  • Service Type は、4 つある。
    • Request-Driven Web Service (App Runner)
    • Load Balanced Web Service (Internet to ECS on Fargate)
    • Backend Service (ECS on Fargate)
    • Worker Service (Events to SQS to ECS on Fargate)

Job

  • Job とは、スケジュール実行される Job です。

Pipeline

  • Pipelineとは、Service、Job のパイプラインを扱うものです。
  • Copilot を使って CodePipeline の構築ができたら、あとは GitHub、Bitbucket、CodeCommit リポジトリにコードをプッシュするだけです。あとは CodePipeline がデプロイまでのプロセスを実行してくれます。

試してみた

  • まずは、Copilot CLI のインストールから始めます。
  • AWS Copilot は Homebrew もしくはバイナリのダウンロードでインストールできるので、今回は Homebrew を用いてインストールしていきます。
brew install aws/tap/copilot-cli
  • 使用する Dockerfile は下記で進めていこうと思います。
FROM nginx:alpine
EXPOSE 80
COPY . /usr/share/nginx/html
  • この Dockerfile は、NGINX を持っている既存のコンテナイメージを使い、そこにいくつかの HTML ファイルを追加して新しいコンテナイメージを作ることを Docker に指示しています。
  • 2行目の EXPOSE という命令文によって Copilot はどのポート番号を LB 経由で公開すればよいかを判断します。
  • Dokcerfile と起動させるアプリケーションの準備ができたら、次は下記のコマンドを利用してそれらを AWS にデプロイします。
  • また、Copilot はコマンドを実行したディレクトリに存在する Dockerfile を自動的に検出します。
copilot init
> copilot init
Note: It's best to run this command in the root of your Git repository.
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: test
Workload type: Request-Driven Web Service
Service name: test-service
Dockerfile: ./Dockerfile
Ok great, we'll set up a Request-Driven Web Service named test-service in application test listening on port 80.

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

Note: Architecture type arm64 has been detected. At this time, arm64 architectures are not supported for App Runner workloads. We will set platform 'linux/x86_64' instead.
✔ Wrote the manifest for service test-service at copilot/test-service/manifest.yml
Your manifest contains configurations like your container size and port (:80).

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

✔ Wrote the manifest for environment test at copilot/environments/test/manifest.yml
- Update regional resources with stack set "test-infrastructure"  [succeeded]  [0.0s]
- Update regional resources with stack set "test-infrastructure"  [succeeded]        [130.5s]
  - Update resources in region "ap-northeast-1"                   [create complete]  [130.8s]
    - KMS key to encrypt pipeline artifacts between stages        [create complete]  [121.5s]
    - ECR container image repository for "test-service"           [create complete]  [0.0s]
    - S3 Bucket to store local artifacts                          [create complete]  [1.8s]
✔ Proposing infrastructure changes for the test-test environment.
- Creating the infrastructure for the test-test environment.  [create complete]  [88.2s]
  - An IAM Role for AWS CloudFormation to manage resources    [create complete]  [42.1s]
  - An IAM Role to describe resources in your environment     [create complete]  [42.3s]
✔ Provisioned bootstrap resources for environment test in region ap-northeast-1 under application test.
✔ Provisioned bootstrap resources for environment test.
✔ Proposing infrastructure changes for the test-test environment.
- Creating the infrastructure for the test-test environment.                  [update complete]  [77.2s]
  - An ECS cluster to group your services                                     [create complete]  [2.4s]
  - 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]  [20.3s]
  - Private subnet 1 for resources with no internet access                    [create complete]  [4.2s]
  - Private subnet 2 for resources with no internet access                    [create complete]  [2.3s]
  - A custom route table that directs network traffic for the public subnets  [create complete]  [9.3s]
  - Public subnet 1 for resources that can access the internet                [create complete]  [2.3s]
  - Public subnet 2 for resources that can access the internet                [create complete]  [8.1s]
  - A private DNS namespace for discovering services within the environment   [create complete]  [43.8s]
  - A Virtual Private Cloud to control networking of your AWS resources       [create complete]  [12.9s]
  • おおおできてますね!!

  • コマンド一発でデプロイまでできちゃいました、感動です。。
    スクリーンショット 2022-12-06 19.01.52.png

  • 画面表示も良さそう!
    スクリーンショット 2022-12-06 19.02.44.png

参考文献

18
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
8