AWSコパイロットを使用して、Amazon ECS の開始方法 - Amazon Elastic Container Service

AWSコパイロットを使用して、Amazon ECS の開始方法

AWSAmazon ECS アプリケーションをデプロイしてコパイロットを使用して、Amazon ECS の使用を開始する

前提条件

開始する前に、以下の前提条件を満たしていることを確認してください。

  • AWS アカウントをセットアップします。詳細については、「Amazon ECS を使用するようにセットアップする」を参照してください。

  • AWSコパイロット CLIのインストール。現在、リリースは Linux および macOS システムをサポートしています。詳細については、「AWS Copilot CLI のインストール」を参照してください。

  • AWS CLI をインストールして設定します。詳細については、「AWS コマンドラインインターフェイス」を参照してください。

  • aws configure を実行して、AWSコパイロット CLI がアプリケーションとサービスの管理に使用するデフォルトプロファイルを設定します。

  • Docker のインストールと実行 詳細については、「Docker の開始方法」を参照してください。

1 つのコマンドを使用してアプリケーションをデプロイする

起動する前に、AWS コマンドラインツールがインストールされており、aws configure が実行済みであることを確認してください。

次のコマンドを使用して、アプリケーションをデプロイします。

git clone https://github.com/aws-samples/amazon-ecs-cli-sample-app.git demo-app && \ cd demo-app && \ copilot init --app demo \ --name api \ --type 'Load Balanced Web Service' \ --dockerfile './Dockerfile' \ --port 80 \ --deploy

アプリケーションをステップバイステップでデプロイする

ステップ 1: 認証情報を設定する

aws configure を実行して、AWSコパイロット CLI がアプリケーションとサービスの管理に使用するデフォルトプロファイルを設定します。

aws configure

ステップ 2: デモアプリのクローンを作成する

単純なフラスコアプリケーションと Dockerfile のクローンを作成します。

git clone https://github.com/aws-samples/amazon-ecs-cli-sample-app.git demo-app

ステップ 3: アプリケーションをセットアップする

  1. demo-app ディレクトリ内から、init コマンドを実行します。

    Windows ユーザーの場合は、ダウンロードした copilot.exe ファイルを含むフォルダから init コマンドを実行します。

    copilot init

    AWSコパイロット では、次のステップから始めて、一連の端末プロンプトを使用して、最初のアプリケーションとサービスのセットアップを順を追って説明します。AWS コパイロットすでにを使用してアプリケーションをデプロイしている場合は、アプリケーション名のリストからアプリケーションを選択するように求められます。

  2. アプリケーションに名前を付ける

    What would you like to name your application? [? for help]

    Enter demo.

ステップ 4:「デモ」アプリケーションで ECS サービスをセットアップする

  1. サービスタイプを選択するよう求められます。小さな API を提供するシンプルな Flask アプリケーションを構築しています。

    Which service type best represents your service's architecture? [Use arrows to move, type to filter, ? for more help] > Load Balanced Web Service Backend Service Scheduled Job

    Choose Load Balanced Web Service .

  2. サービスの名前を指定します。

    What do you want to name this Load Balanced Web Service? [? for help]

    サービスの名前の場合、Enter api

  3. ドッカーファイルを選択します。

    Which Dockerfile would you like to use for api? [Use arrows to move, type to filter, ? for more help] > ./Dockerfile Use an existing image instead

    Choose Dockerfile.

    Windows ユーザーの場合は、Dockerfile へのパスを demo-app folder (*`...\demo-app\Dockerfile`*\.) に入力します。

  4. ポートを定義します。

    Which port do you want customer traffic sent to? [? for help] (80)

    Enter 80、またはデフォルトを受け入れます。

  5. 作成中のアプリケーションリソースを示すログが見られます。

    Creating the infrastructure to manage services under application demo.
  6. アプリケーションリソースが作成されたら、テスト環境をデプロイします。

    Would you like to deploy a test environment? [? for help] (y/N)

    Enter y.

    Proposing infrastructure changes for the test environment.
  7. アプリケーションデプロイのステータスを示すログが見られます。

    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 an application on ECS. An application is a collection of containerized services that operate together. Use existing application: No Application name: demo Workload type: Load Balanced Web Service Service name: api Dockerfile: ./Dockerfile no EXPOSE statements in Dockerfile ./Dockerfile Port: 80 Ok great, we'll set up a Load Balanced Web Service named api in application demo listening on port 80. ✔ Created the infrastructure to manage services under application demo. ✔ Wrote the manifest for service api at copilot/api/manifest.yml Your manifest contains configurations like your container size and port (:80). ✔ Created ECR repositories for service api. 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 [Complete] - Virtual private cloud on 2 availability zones to hold your services [Complete] - Internet gateway to connect the network to the internet [Complete] - Public subnets for internet facing services [Complete] - Private subnets for services that can't be reached from the internet [Complete] - Routing tables for services to talk with each other [Complete] - ECS Cluster to hold your services [Complete] ✔ Linked account aws_account_id and region region to application demo. ✔ Created environment test in region region under application demo. Environment test is already on the latest version v1.0.0, skip upgrade. [+] Building 0.8s (7/7) FINISHED => [internal] load .dockerignore 0.1s => => transferring context: 2B 0.0s => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 37B 0.0s => [internal] load metadata for docker.io/library/nginx:latest 0.7s => [internal] load build context 0.0s => => transferring context: 32B 0.0s => [1/2] FROM docker.io/library/nginx@sha256:aeade65e99e5d5e7ce162833636f692354c227ff438556e5f3ed0335b7cc2f1b 0.0s => CACHED [2/2] COPY index.html /usr/share/nginx/html 0.0s => exporting to image 0.0s => => exporting layers 0.0s => => writing image sha256:3ee02fd4c0f67d7bd808ed7fc73263880649834cbb05d5ca62380f539f4884c4 0.0s => => naming to aws_account_id.dkr.ecr.region.amazonaws.com/demo/api:cee7709 0.0s WARNING! Your password will be stored unencrypted in /home/user/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded The push refers to repository [aws_account_id.dkr.ecr.region.amazonaws.com/demo/api] 592a5c0c47f1: Pushed 6c7de695ede3: Pushed 2f4accd375d9: Pushed ffc9b21953f4: Pushed cee7709: digest: sha_digest ✔ Deployed api, you can access it at http://demo-Publi-1OQ8VMS2VC2WG-561733989.region.elb.amazonaws.com.

ステップ 5: アプリケーションが実行されていることを検証する

次のコマンドを使用して、アプリケーションのステータスを表示します。

AWS コパイロットのアプリケーションを一覧を表示します。

copilot app ls

アプリケーション内の環境およびサービスに関する情報を表示します。

copilot app show

環境に関する情報を表示します。

copilot env ls

エンドポイント、キャパシティー、関連リソースなど、サービスに関する情報を表示します。

copilot svc show

アプリケーション内のすべてのサービスのリスト。

copilot svc ls

デプロイされたサービスのログを表示します。

copilot svc logs

サービスのステータスを表示する

copilot svc status

使用可能なコマンドとオプションを一覧表示します。

copilot --help
copilot init --help

ステップ 6。CI/CD パイプラインの作成方法を学ぶ

AWS コパイロットを使用して CI/CD パイプラインと git ワークフローを完全に自動化する方法についての詳細は、「ECSワークショップ」を参照してください。

ステップ 7: クリーンアップする

次のコマンドを実行して、すべてのリソースを削除およびクリーンアップします。

copilot app delete