Amazon Elastic Container Service
开发人员指南 (API 版本 2014-11-13)
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门

任务元数据终端节点版本 2

从 1.17.0 版 Amazon ECS 容器代理开始,各种任务元数据和 Docker 统计数据都可用于那些在 Amazon ECS 容器代理所提供的 HTTP 终端节点上使用 awsvpc 网络模式的任务。

所有属于使用 awsvpc 网络模式启动的任务的容器都会收到预定义本地链路地址范围内的一个本地 IPv4 地址。当一个容器查询元数据终端节点时,Amazon ECS 容器代理会基于该容器的唯一 IP 地址确定容器属于哪个任务,并返回有关该任务的元数据和统计数据。

启用任务元数据

为以下任务默认启用任务元数据版本 2 功能:

  • 使用 Fargate 启动类型并使用平台版本 v1.1.0 或更高版本的任务。有关更多信息,请参阅AWS Fargate 平台版本

  • 使用 EC2 启动类型、还使用 awsvpc 网络模式并在最低运行 1.17.0 版的 Amazon ECS 容器代理的 Amazon EC2 基础设施上启动的任务。有关更多信息,请参阅Amazon ECS 容器代理版本

您可以通过将代理更新为最新版本来增加在旧容器实例上对于该功能的支持。有关更多信息,请参阅 更新 Amazon ECS 容器代理

任务元数据终端节点路径

以下 API 终端节点可用于容器:

169.254.170.2/v2/metadata

此终端节点返回任务的元数据 JSON,包括与任务相关的所有容器的 ID 和名称列表。有关此终端节点响应的更多信息,请参阅任务元数据 JSON 响应

169.254.170.2/v2/metadata/<container-id>

此终端节点为指定 Docker 容器 ID 返回元数据 JSON。

169.254.170.2/v2/stats

此终端节点为所有与此任务相关的容器返回 Docker 统计信息 JSON。有关每个返回的统计信息的更多信息,请参阅 Docker API 文档中的 ContainerStats

169.254.170.2/v2/stats/<container-id>

此终端节点为指定 Docker 容器 ID 返回 Docker 统计数据 JSON。有关每个返回的统计信息的更多信息,请参阅 Docker API 文档中的 ContainerStats

任务元数据 JSON 响应

以下信息返回自任务元数据终端节点 (169.254.170.2/v2/metadata) JSON 响应。

Cluster

The Amazon ECS cluster to which the task belongs.

TaskARN

The full Amazon Resource Name (ARN) of the task to which the container belongs.

Family

The family of the Amazon ECS task definition for the task.

Revision

The revision of the Amazon ECS task definition for the task.

DesiredStatus

The desired status for the task from Amazon ECS.

KnownStatus

The known status for the task from Amazon ECS.

Containers

A list of container metadata for each container associated with the task.

DockerId

The Docker ID for the container.

Name

The name of the container as specified in the task definition.

DockerName

The name of the container supplied to Docker. The Amazon ECS container agent generates a unique name for the container to avoid name collisions when multiple copies of the same task definition are run on a single instance.

Image

The image for the container.

ImageID

The SHA-256 digest for the image.

Ports

Any ports exposed for the container. This parameter is omitted if there are no exposed ports.

Labels

Any labels applied to the container. This parameter is omitted if there are no labels applied.

DesiredStatus

The desired status for the container from Amazon ECS.

KnownStatus

The known status for the container from Amazon ECS.

ExitCode

The exit code for the container. This parameter is omitted if the container has not exited.

Limits

The resource limits specified at the container level (such as CPU and memory). This parameter is omitted if no resource limits are defined.

CreatedAt

The time stamp for when the container was created. This parameter is omitted if the container has not been created yet.

StartedAt

The time stamp for when the container started. This parameter is omitted if the container has not started yet.

FinishedAt

The time stamp for when the container stopped. This parameter is omitted if the container has not stopped yet.

Type

The type of the container. Containers that are specified in your task definition are of type NORMAL. You can ignore other container types, which are used for internal task resource provisioning by the Amazon ECS container agent.

Networks

The network information for the container, such as the network mode and IP address. This parameter is omitted if no network information is defined.

Limits

The resource limits specified at the task level (such as CPU and memory). This parameter is omitted if no resource limits are defined.

PullStartedAt

The time stamp for when the first container image pull began.

PullStoppedAt

The time stamp for when the last container image pull finished.

ExecutionStoppedAt

The time stamp for when the tasks DesiredStatus moved to STOPPED. This occurs when an essential container moves to STOPPED.

AvailabilityZone

The Availability Zone the task is in.

任务元数据响应示例

The following JSON response is for a single-container task.

{ "Cluster": "default", "TaskARN": "arn:aws:ecs:us-east-2:012345678910:task/9781c248-0edd-4cdb-9a93-f63cb662a5d3", "Family": "nginx", "Revision": "5", "DesiredStatus": "RUNNING", "KnownStatus": "RUNNING", "Containers": [ { "DockerId": "731a0d6a3b4210e2448339bc7015aaa79bfe4fa256384f4102db86ef94cbbc4c", "Name": "~internal~ecs~pause", "DockerName": "ecs-nginx-5-internalecspause-acc699c0cbf2d6d11700", "Image": "amazon/amazon-ecs-pause:0.1.0", "ImageID": "", "Labels": { "com.amazonaws.ecs.cluster": "default", "com.amazonaws.ecs.container-name": "~internal~ecs~pause", "com.amazonaws.ecs.task-arn": "arn:aws:ecs:us-east-2:012345678910:task/9781c248-0edd-4cdb-9a93-f63cb662a5d3", "com.amazonaws.ecs.task-definition-family": "nginx", "com.amazonaws.ecs.task-definition-version": "5" }, "DesiredStatus": "RESOURCES_PROVISIONED", "KnownStatus": "RESOURCES_PROVISIONED", "Limits": { "CPU": 0, "Memory": 0 }, "CreatedAt": "2018-02-01T20:55:08.366329616Z", "StartedAt": "2018-02-01T20:55:09.058354915Z", "Type": "CNI_PAUSE", "Networks": [ { "NetworkMode": "awsvpc", "IPv4Addresses": [ "10.0.2.106" ] } ] }, { "DockerId": "43481a6ce4842eec8fe72fc28500c6b52edcc0917f105b83379f88cac1ff3946", "Name": "nginx-curl", "DockerName": "ecs-nginx-5-nginx-curl-ccccb9f49db0dfe0d901", "Image": "nrdlngr/nginx-curl", "ImageID": "sha256:2e00ae64383cfc865ba0a2ba37f61b50a120d2d9378559dcd458dc0de47bc165", "Labels": { "com.amazonaws.ecs.cluster": "default", "com.amazonaws.ecs.container-name": "nginx-curl", "com.amazonaws.ecs.task-arn": "arn:aws:ecs:us-east-2:012345678910:task/9781c248-0edd-4cdb-9a93-f63cb662a5d3", "com.amazonaws.ecs.task-definition-family": "nginx", "com.amazonaws.ecs.task-definition-version": "5" }, "DesiredStatus": "RUNNING", "KnownStatus": "RUNNING", "Limits": { "CPU": 512, "Memory": 512 }, "CreatedAt": "2018-02-01T20:55:10.554941919Z", "StartedAt": "2018-02-01T20:55:11.064236631Z", "Type": "NORMAL", "Networks": [ { "NetworkMode": "awsvpc", "IPv4Addresses": [ "10.0.2.106" ] } ] } ], "PullStartedAt": "2018-02-01T20:55:09.372495529Z", "PullStoppedAt": "2018-02-01T20:55:10.552018345Z", "AvailabilityZone": "us-east-2b" }