[小ネタ] ECS でタスクの作成時刻を確認する方法

2023.05.01

アノテーション・テクニカルサポートチームの hato です。

ECS のコンソールが新しくなり、タスクの作成時刻を確認する箇所も変わっていたので、ご紹介します。

やってみた

Amazon ECS コンソールの「クラスター」からタスクが含まれるクラスターを選択します。

「タスク」タブを選択します。

確認したいタスク IDを選択します。

「タスクの概要」セクションの右端に「開始時刻」と「作成時刻」が表示されます。

AWS CLIから確認する場合

list-tasksコマンドを実行して確認したいタスクのtaskArnを取得します。

$ aws ecs list-tasks \
     --cluster 【ECS クラスター名】
{
    "taskArns": [
        "arn:aws:ecs:ap-northeast-1:123456789012:task/hato-cluster/d721395131ab43ed81f83cacd713c5b7"
    ]
}

describe-tasksコマンドを実行して、「開始時刻(startedAt) 」と「作成時刻(createdAt)」を確認します。

$ aws ecs describe-tasks \
     --cluster 【ECS クラスター名】 \
     --tasks 【taskArn】
{
  "tasks": [
    {
      "attachments": [
        {
          "id": "c6d061cd-533f-4e9f-8ddb-3a5d79d7e050",
          "type": "ElasticNetworkInterface",
          "status": "ATTACHED",
          "details": [
            {
              "name": "subnetId",
              "value": "subnet-01234567890123456"
            },
            {
              "name": "networkInterfaceId",
              "value": "eni-0e04a9ab5e8b56349"
            },
            {
              "name": "macAddress",
              "value": "00:11:22:33:44:55"
            },
            {
              "name": "privateDnsName",
              "value": "ip-10-0-0-1.ap-northeast-1.compute.internal"
            },
            {
              "name": "privateIPv4Address",
              "value": "10.0.0.1"
            }
          ]
        }
      ],
      "attributes": [
        {
          "name": "ecs.cpu-architecture",
          "value": "x86_64"
        }
      ],
      "availabilityZone": "ap-northeast-1a",
      "clusterArn": "arn:aws:ecs:ap-northeast-1:123456789012:cluster/hato-cluster",
      "connectivity": "CONNECTED",
      "connectivityAt": "2023-05-01T10:02:38.065000+09:00",
      "containers": [
        {
          "containerArn": "arn:aws:ecs:ap-northeast-1:123456789012:container/hato-cluster/d721395131ab43ed81f83cacd713c5b7/b6392a74-5566-4d11-a87c-508c732172f0",
          "taskArn": "arn:aws:ecs:ap-northeast-1:123456789012:task/hato-cluster/d721395131ab43ed81f83cacd713c5b7",
          "name": "nginx",
          "image": "public.ecr.aws/nginx/nginx:stable",
          "imageDigest": "sha256:89c77e7e015f5b3e691324fd59ecd938fd82d419adcd87385676e7f763d1a3e2",
          "runtimeId": "123456c124284ea6bc488f7a3be8c3c2-2531612879",
          "lastStatus": "RUNNING",
          "networkBindings": [],
          "networkInterfaces": [
            {
              "attachmentId": "c6d061cd-533f-4e9f-8ddb-3a5d79d7e050",
              "privateIpv4Address": "10.0.0.1"
            }
          ],
          "healthStatus": "UNKNOWN",
          "managedAgents": [
            {
              "lastStartedAt": "2023-05-01T10:03:10.978000+09:00",
              "name": "ExecuteCommandAgent",
              "lastStatus": "RUNNING"
            }
          ],
          "cpu": "0"
        }
      ],
      "cpu": "256",
      "createdAt": "2023-05-01T10:02:34.656000+09:00",
      "desiredStatus": "RUNNING",
      "enableExecuteCommand": true,
      "group": "service:hato-service",
      "healthStatus": "UNKNOWN",
      "lastStatus": "RUNNING",
      "launchType": "FARGATE",
      "memory": "512",
      "overrides": {
        "containerOverrides": [
          {
            "name": "nginx"
          }
        ],
        "inferenceAcceleratorOverrides": []
      },
      "platformVersion": "1.4.0",
      "platformFamily": "Linux",
      "pullStartedAt": "2023-05-01T10:02:49.202000+09:00",
      "pullStoppedAt": "2023-05-01T10:02:54.310000+09:00",
      "startedAt": "2023-05-01T10:02:56.726000+09:00",
      "startedBy": "ecs-svc/4197414922177771410",
      "tags": [],
      "taskArn": "arn:aws:ecs:ap-northeast-1:123456789012:task/hato-cluster/d721395131ab43ed81f83cacd713c5b7",
      "taskDefinitionArn": "arn:aws:ecs:ap-northeast-1:123456789012:task-definition/hato-ecs-task:1",
      "version": 3,
      "ephemeralStorage": {
        "sizeInGiB": 20
      }
    }
  ],
  "failures": []
}

参考資料

アノテーション株式会社について

アノテーション株式会社は、クラスメソッド社のグループ企業として「オペレーション・エクセレンス」を担える企業を目指してチャレンジを続けています。「らしく働く、らしく生きる」のスローガンを掲げ、様々な背景をもつ多様なメンバーが自由度の高い働き方を通してお客様へサービスを提供し続けてきました。現在当社では一緒に会社を盛り上げていただけるメンバーを募集中です。少しでもご興味あれば、アノテーション株式会社WEBサイトをご覧ください。