Docker on Amazon Web Services
上QQ阅读APP看书,第一时间看更新

Verifying the ECS agent

The ECS agent includes a local web server that can be used to introspect current ECS agent status.

The following example demonstrates introspecting the ECS agent using the curl command:

> curl -s localhost:51678 | jq
{
"AvailableCommands": [
"/v1/metadata",
"/v1/tasks",
"/license"
]
}
> curl -s localhost:51678/v1/metadata | jq
{
"Cluster": "test-cluster",
"ContainerInstanceArn": "arn:aws:ecs:us-east-1:385605022855:container-instance/f67cbfbd-1497-47c0-b56c-a910c923ba70",
"Version": "Amazon ECS Agent - v1.16.2 (998c9b5)"
}
Introspecting the ECS Agent

Notice that the ECS agent listens on port 51678 and provides three endpoints you can query:

  • /v1/metadata: Describes the cluster the container instance is joined to, the container instance Amazon Resource Name (ARN), and the ECS agent version
  • /v1/tasks: Returns a list of currently-running tasks. At the moment we haven't deployed any ECS services or tasks to our cluster, hence this list is empty
  • /license: Provides the various software licenses that apply for the ECS agent software

The /v1/metadata endpoint is particularly useful, as you can use this endpoint to determine whether or not the ECS agent has successfully joined a given ECS cluster. We will use this later on in Chapter 6, Building Custom ECS Container Instances to perform a health check on instance creation to ensure our instances have successfully joined the correct ECS cluster.