#
ドキュメント

Document

自分のための備忘録です。

ECSのイベント

Notification by Chatbot

https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/ecs_cwe_events.html

※ その他のサービスのイベントについては以下を参照
https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-service-event.html

イベントの種類

  • コンテナインスタンスの状態変更イベント
  • タスク状態変更イベント
  • サービスアクションイベント

イベント一覧

タスク状態変更イベントは、次の形式で配信されます。以下の「detail」セクションは、Amazon Elastic Container Service API Reference の DescribeTasks API オペレーションから返される Task オブジェクトに似ています。コンテナが Amazon ECR でホストされているイメージを使用している場合は、imageDigest フィールドが返されます。

https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/ecs_cwe_events.html

例)

発生したイベントを知る方法

EventBridge > イベント > ルール のターゲットにCloudWatch ロググループを指定

イベントルール

注意

{
  "source": [
    "aws.ecs"
  ],
  "detail-type": [
    "ECS Task State Change"
  ]
}
  • detail-typeは上記のように配列
  • "detail-type": "ECS Task State Change"ではエラー

Event

成功

{
    "version": "0",
    "id": "92b591a6-45be-dcff-a9ed-41042372dabf",
    "detail-type": "ECS Task State Change",
    "source": "aws.ecs",
    "account": "832665068462",
    "time": "2021-07-12T05:44:09Z",
    "region": "ap-northeast-1",
    "resources": [
        "arn:aws:ecs:ap-northeast-1:832665068462:task/apline-hello-cluster/ff259f15925142589b40c1756e6a0b62"
    ],
    "detail": {
        "attachments": [
            {
                "id": "d5f3beb9-254a-480b-97db-94a04e1863f1",
                "type": "eni",
                "status": "DELETED",
                "details": [
                    {
                        "name": "subnetId",
                        "value": "subnet-b847c693"
                    },
                    {
                        "name": "networkInterfaceId",
                        "value": "eni-0272386519f4df8b6"
                    },
                    {
                        "name": "macAddress",
                        "value": "0e:27:11:4e:d9:ef"
                    },
                    {
                        "name": "privateDnsName",
                        "value": "ip-172-31-24-54.ap-northeast-1.compute.internal"
                    },
                    {
                        "name": "privateIPv4Address",
                        "value": "172.31.24.54"
                    }
                ]
            }
        ],
        "availabilityZone": "ap-northeast-1d",
        "clusterArn": "arn:aws:ecs:ap-northeast-1:832665068462:cluster/apline-hello-cluster",
        "connectivity": "CONNECTED",
        "connectivityAt": "2021-07-12T05:43:33.739Z",
        "containers": [
            {
                "containerArn": "arn:aws:ecs:ap-northeast-1:832665068462:container/apline-hello-cluster/ff259f15925142589b40c1756e6a0b62/7f0af8bb-6da5-40ad-b473-726d6721124c",
                "exitCode": 0,
                "lastStatus": "STOPPED",
                "name": "alpine-hello",
                "image": "832665068462.dkr.ecr.ap-northeast-1.amazonaws.com/alpine-hello:latest",
                "imageDigest": "sha256:3442d9824b2a7fa7fdd33e9ea63f9f0efa6ad6cde28938f442d1bf4f4e65135e",
                "runtimeId": "ff259f15925142589b40c1756e6a0b62-2309530183",
                "taskArn": "arn:aws:ecs:ap-northeast-1:832665068462:task/apline-hello-cluster/ff259f15925142589b40c1756e6a0b62",
                "networkInterfaces": [
                    {
                        "attachmentId": "d5f3beb9-254a-480b-97db-94a04e1863f1",
                        "privateIpv4Address": "172.31.24.54"
                    }
                ],
                "cpu": "0"
            }
        ],
        "cpu": "256",
        "createdAt": "2021-07-12T05:43:29.769Z",
        "desiredStatus": "STOPPED",
        "enableExecuteCommand": false,
        "ephemeralStorage": {
            "sizeInGiB": 20
        },
        "executionStoppedAt": "2021-07-12T05:43:46.186Z",
        "group": "family:apline-hello-task-definition",
        "launchType": "FARGATE",
        "lastStatus": "STOPPED",
        "memory": "512",
        "overrides": {
            "containerOverrides": [
                {
                    "name": "alpine-hello"
                }
            ]
        },
        "platformVersion": "1.4.0",
        "pullStartedAt": "2021-07-12T05:43:43.735Z",
        "pullStoppedAt": "2021-07-12T05:43:44.537Z",
        "startedAt": "2021-07-12T05:43:46.206Z",
        "stoppingAt": "2021-07-12T05:43:56.246Z",
        "stoppedAt": "2021-07-12T05:44:09.312Z",
        "stoppedReason": "Essential container in task exited",
        "stopCode": "EssentialContainerExited",
        "taskArn": "arn:aws:ecs:ap-northeast-1:832665068462:task/apline-hello-cluster/ff259f15925142589b40c1756e6a0b62",
        "taskDefinitionArn": "arn:aws:ecs:ap-northeast-1:832665068462:task-definition/apline-hello-task-definition:1",
        "updatedAt": "2021-07-12T05:44:09.312Z",
        "version": 5
    }
}

失敗

{
    "version": "0",
    "id": "5474991e-82e2-c6ae-667d-b974dc63d14b",
    "detail-type": "ECS Task State Change",
    "source": "aws.ecs",
    "account": "832665068462",
    "time": "2021-07-12T05:49:02Z",
    "region": "ap-northeast-1",
    "resources": [
        "arn:aws:ecs:ap-northeast-1:832665068462:task/apline-hello-cluster/c21689e7106841b49f9c180dacd78121"
    ],
    "detail": {
        "attachments": [
            {
                "id": "330cca24-63a9-49c0-8d9f-d019aa78cf48",
                "type": "eni",
                "status": "DELETED",
                "details": [
                    {
                        "name": "subnetId",
                        "value": "subnet-589c2210"
                    },
                    {
                        "name": "networkInterfaceId",
                        "value": "eni-05ec42316e76ac811"
                    },
                    {
                        "name": "macAddress",
                        "value": "06:34:ed:77:66:4b"
                    },
                    {
                        "name": "privateDnsName",
                        "value": "ip-172-31-34-167.ap-northeast-1.compute.internal"
                    },
                    {
                        "name": "privateIPv4Address",
                        "value": "172.31.34.167"
                    }
                ]
            }
        ],
        "availabilityZone": "ap-northeast-1a",
        "clusterArn": "arn:aws:ecs:ap-northeast-1:832665068462:cluster/apline-hello-cluster",
        "connectivity": "CONNECTED",
        "connectivityAt": "2021-07-12T05:46:54.258Z",
        "containers": [
            {
                "containerArn": "arn:aws:ecs:ap-northeast-1:832665068462:container/apline-hello-cluster/c21689e7106841b49f9c180dacd78121/584ae525-3ac8-4173-a69e-a63036ddd77e",
                "lastStatus": "STOPPED",
                "name": "alpine-hello",
                "image": "832665068462.dkr.ecr.ap-northeast-1.amazonaws.com/alpine-hello:latest",
                "runtimeId": "c21689e7106841b49f9c180dacd78121-2309530183",
                "taskArn": "arn:aws:ecs:ap-northeast-1:832665068462:task/apline-hello-cluster/c21689e7106841b49f9c180dacd78121",
                "networkInterfaces": [
                    {
                        "attachmentId": "330cca24-63a9-49c0-8d9f-d019aa78cf48",
                        "privateIpv4Address": "172.31.34.167"
                    }
                ],
                "cpu": "0"
            }
        ],
        "cpu": "256",
        "createdAt": "2021-07-12T05:46:50.122Z",
        "desiredStatus": "STOPPED",
        "enableExecuteCommand": false,
        "ephemeralStorage": {
            "sizeInGiB": 20
        },
        "executionStoppedAt": "2021-07-12T05:48:39.194Z",
        "group": "family:apline-hello-task-definition",
        "launchType": "FARGATE",
        "lastStatus": "STOPPED",
        "memory": "512",
        "overrides": {
            "containerOverrides": [
                {
                    "name": "alpine-hello"
                }
            ]
        },
        "platformVersion": "1.4.0",
        "stoppingAt": "2021-07-12T05:48:49.236Z",
        "stoppedAt": "2021-07-12T05:49:02.208Z",
        "stoppedReason": "ResourceInitializationError: unable to pull secrets or registry auth: pull command failed: : signal: killed",
        "stopCode": "TaskFailedToStart",
        "taskArn": "arn:aws:ecs:ap-northeast-1:832665068462:task/apline-hello-cluster/c21689e7106841b49f9c180dacd78121",
        "taskDefinitionArn": "arn:aws:ecs:ap-northeast-1:832665068462:task-definition/apline-hello-task-definition:1",
        "updatedAt": "2021-07-12T05:49:02.208Z",
        "version": 4
    }
}