Cats task definition

先ほどweb用のタスク定義を作成しましたが、catsタスク定義の作成方法もほぼ同じです。catsweb の唯一の違いは、Amazon ECSがAmazon CloudWatch Logsにログを送信するためのコンテナ・ログ・ルーターである FireLens を設定することです。

cats 用タスク定義の作成

  1. Amazon ECSタスク定義に移動して新規作成する。
  2. 起動タイプの互換性として EC2 を選択します。 SelectEC2
  3. タスク定義名: catsdef

    FireLens の設定

    FireLens の有効化

  4. 「Log Router Integration」をスクロールダウンし、「Enable Firelens Intigration」にチェックを入れ Apply を選択します。

AWS は、CloudWatch LogsとKinesis Data Firehoseの両方に対応したプラグインを持つFluent Bitイメージを提供しています。Fluentdに比べてリソース使用率が低いため、ログルーターとしてFluent Bitを使用することをお勧めします。詳しくは、CloudWatch Logs for Fluent Bitおよび Amazon Kinesis Firehose for Fluent Bit.をご覧ください。

EnableFireLens

*Container Definitions*までスクロールして、log_routerコンテナが作成されているかどうかを確認します。 CheckLogRouter

log_router コンテナのロギングの設定

log_routerコンテナをクリックし、Advanced container configuration - STORAGE AND LOGGING までスクロールダウンしてログ関連の設定をします。 5. ログの設定を行います。「Auto-configure CloudWatch Logs」のチェックを外します。 6. ログドライバとオプションの設定を以下のように選びます。 LogConfig - Log driver: awslogs - Log options: 以下の値をコピーアンドペーストを推奨します。

Key Value Input
awslogs-group Value firelens-container
awslogs-region Value us-east-1
awslogs-stream-prefix Value firelens
awslogs-create-group Value true
  1. 最後までスクロールして、「Update」をクリックします。

cats コンテナの追加

*Container Definitions*に戻り、Add containerをクリックしてcats コンテナを追加します。 CatsTask 8. cats コンテナの設定をします。 - Container name: cats - Image: cats イメージの latest URI

新しいブラウザタブを開き、ECRに移動します。catsリポジトリを選択し、latestタグ付きイメージのボタンをクリックします。

CatsLatest - Memory Limits - Hard limit 128 - Port mappings + Host port: 0 + Container port: 80 (tcp)

cats コンテナのログ関連の設定方法

Advanced container configuration - STORAGE AND LOGGING までスクロールダウンし、cats コンテナのロギングを設定します。

  1. ログの設定を行います。Auto-configure Cloudwatch Logsのチェックを外します。
  2. ログドライバとオプションを設定します。 CatsLogConfig
  3. Log driver: awsfirelens
  4. Log options
Key Value Input
Name Value cloudwatch
log_group_name Value ecs-demogo-log
log_stream_prefix Value from-fluent-bit
region Value us-east-1
auto_create_group Value true
  1. Addをクリックすると、ウィンドウが閉じます。その後catsコンテナが追加されたことを確認します。
  2. Createをクリックします。

また、以下のテンプレートをコピー&ペーストするだけで、コンソールから同じcatsタスク定義を作成したり、ファイルに保存してAWS CLIの–cli-input-jsonオプションで使用したりすることができます。

{
  "ipcMode": null,
  "executionRoleArn": null,
  "containerDefinitions": [
    {
      "dnsSearchDomains": null,
      "environmentFiles": null,
      "logConfiguration": null,
      "entryPoint": null,
      "portMappings": [],
      "command": null,
      "linuxParameters": null,
      "cpu": 0,
      "environment": [],
      "resourceRequirements": null,
      "ulimits": null,
      "dnsServers": null,
      "mountPoints": [],
      "workingDirectory": null,
      "secrets": null,
      "dockerSecurityOptions": null,
      "memory": null,
      "memoryReservation": 50,
      "volumesFrom": [],
      "stopTimeout": null,
      "image": "906394416424.dkr.ecr.ap-northeast-2.amazonaws.com/aws-for-fluent-bit:latest",
      "startTimeout": null,
      "firelensConfiguration": {
        "type": "fluentbit",
        "options": null
      },
      "dependsOn": null,
      "disableNetworking": null,
      "interactive": null,
      "healthCheck": null,
      "essential": true,
      "links": null,
      "hostname": null,
      "extraHosts": null,
      "pseudoTerminal": null,
      "user": "0",
      "readonlyRootFilesystem": null,
      "dockerLabels": null,
      "systemControls": null,
      "privileged": null,
      "name": "log_router"
    },
    {
      "dnsSearchDomains": null,
      "environmentFiles": null,
      "logConfiguration": {
        "logDriver": "awsfirelens",
        "secretOptions": null,
        "options": {
          "log_group_name": "ecs-demogo-log",
          "auto_create_group": "true",
          "log_stream_prefix": "from-fluent-bit",
          "region": "us-east-1",
          "Name": "cloudwatch"
        }
      },
      "entryPoint": null,
      "portMappings": [
        {
          "hostPort": 0,
          "protocol": "tcp",
          "containerPort": 80
        }
      ],
      "command": null,
      "linuxParameters": null,
      "cpu": 0,
      "environment": [],
      "resourceRequirements": null,
      "ulimits": null,
      "dnsServers": null,
      "mountPoints": [],
      "workingDirectory": null,
      "secrets": null,
      "dockerSecurityOptions": null,
      "memory": 128,
      "memoryReservation": null,
      "volumesFrom": [],
      "stopTimeout": null,
      "image": "038445823716.dkr.ecr.ap-northeast-2.amazonaws.com/cats:latest",
      "startTimeout": null,
      "firelensConfiguration": null,
      "dependsOn": null,
      "disableNetworking": null,
      "interactive": null,
      "healthCheck": null,
      "essential": true,
      "links": null,
      "hostname": null,
      "extraHosts": null,
      "pseudoTerminal": null,
      "user": null,
      "readonlyRootFilesystem": null,
      "dockerLabels": null,
      "systemControls": null,
      "privileged": null,
      "name": "cats"
    }
  ],
  "placementConstraints": [],
  "memory": null,
  "taskRoleArn": null,
  "compatibilities": [
    "EC2"
  ],
  "taskDefinitionArn": "arn:aws:ecs:ap-northeast-2:038445823716:task-definition/catsdef:16",
  "family": "catsdef",
  "requiresAttributes": [
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.ecr-auth"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "ecs.capability.firelens.fluentbit"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.docker-remote-api.1.21"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.logging-driver.awsfirelens"
    }
  ],
  "pidMode": null,
  "requiresCompatibilities": [
    "EC2"
  ],
  "networkMode": null,
  "cpu": null,
  "revision": 16,
  "status": "ACTIVE",
  "inferenceAccelerators": null,
  "proxyConfiguration": null,
  "volumes": []
}