先ほどweb用のタスク定義を作成しましたが、catsタスク定義の作成方法もほぼ同じです。cats と web の唯一の違いは、Amazon ECSがAmazon CloudWatch Logsにログを送信するためのコンテナ・ログ・ルーターである FireLens を設定することです。
タスク定義名: catsdef
「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.をご覧ください。
*Container Definitions*までスクロールして、log_routerコンテナが作成されているかどうかを確認します。
log_routerコンテナをクリックし、Advanced container configuration - STORAGE AND LOGGING までスクロールダウンしてログ関連の設定をします。
5. ログの設定を行います。「Auto-configure CloudWatch Logs」のチェックを外します。
6. ログドライバとオプションの設定を以下のように選びます。
- 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 |
*Container Definitions*に戻り、Add containerをクリックしてcats コンテナを追加します。
8. cats コンテナの設定をします。
- Container name:
cats
- Image: cats イメージの latest URI
新しいブラウザタブを開き、ECRに移動します。catsリポジトリを選択し、latestタグ付きイメージのボタンをクリックします。
Advanced container configuration - STORAGE AND LOGGING までスクロールダウンし、cats コンテナのロギングを設定します。
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 |
また、以下のテンプレートをコピー&ペーストするだけで、コンソールから同じ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": []
}