Skip to content

Commit fe0de21

Browse files
authored
Merge pull request #41 from iamhopaul123/add-v4-doc
Add doc for v4 metadata usage
2 parents 6b30ca7 + a79e7b7 commit fe0de21

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ This repository contains the source code for the project. To use it, pull the [a
2020
* [Metadata](docs/features.md#metadata)
2121
* [Task Metadata V2](docs/features.md#task-metadata-v2)
2222
* [Task Metadata V3](docs/features.md#task-metadata-v3)
23+
* [Task Metadata V4](docs/features.md#task-metadata-v4)
24+
* [Generic Metadata](docs/features.md#generic-metadata-injection)
2325

2426
#### Security disclosures
2527

docs/features.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,14 @@ V3 Metadata uses the `ECS_CONTAINER_METADATA_URI` environment variable. Unlike V
4848

4949
In most cases, you can set `ECS_CONTAINER_METADATA_URI` to `http://169.254.170.2/v3`.
5050

51-
However, in a few cases, this will not work. This is because the Local Endpoints container needs to be able to determine which container a request for V3 metadata came from. Local Endpoints attempts to use the IP address in the request to determine this. If you use the [example Docker Compose file](examples/docker-compose.yml) with a bridge network, then this IP lookup will work. However, if you use different network settings, then the Local Endpoints will not be able to determine which container a request came from. In this case, set `ECS_CONTAINER_METADATA_URI` to `http://169.254.170.2/v3/containers/{container name}`. The value for `container name` can be any unique substring of your container's name. By setting a custom request URL, the Local Endpoints container can determine which container a request came from.
51+
However, in a few cases, this will not work. This is because the Local Endpoints container needs to be able to determine which container a request for V3 metadata came from. Local Endpoints attempts to use the IP address in the request to determine this. If you use the [example Docker Compose file](../examples/docker-compose.yml) with a bridge network, then this IP lookup will work. However, if you use different network settings, then the Local Endpoints will not be able to determine which container a request came from. In this case, set `ECS_CONTAINER_METADATA_URI` to `http://169.254.170.2/v3/containers/{container name}`. The value for `container name` can be any unique substring of your container's name. By setting a custom request URL, the Local Endpoints container can determine which container a request came from.
52+
53+
#### Task Metadata V4
54+
55+
V4 Metadata uses `ECS_CONTAINER_METADATA_URI_V4` environment variable. In most cases, you can set `ECS_CONTAINER_METADATA_URI_V4` to `http://169.254.170.2/v3`. Similarly, in a few cases when Local Endpoints container doesn't know which container a request came from, you have to set `ECS_CONTAINER_METADATA_URI_V4` to `http://169.254.170.2/v3/containers/{container name}`. Please see the description above on V3 to understand why you'll need to specify the container name in the path.
56+
57+
However, compared to V3, V4 includes additional network metadata when querying the task metadata endpoint (see [here](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v4.html)). Please refer to this [example](../examples/v4) if you want to include those additional V4 metadata. You can use the generic metadata injection feature (described below) to add the additional metadata fields included in V4.
58+
59+
#### Generic Metadata Injection
60+
61+
As mentioned above in the previous section, to inject generic metadata, you'll need to have those additional metadata in JSON files. Then specify paths for the JSON files by using `CONTAINER_METADATA_PATH` and `TASK_METADATA_PATH` environment variables. More specifically, `CONTAINER_METADATA_PATH` is the metadata for each container, which will override their counterparts in the normal response. Also, `TASK_METADATA_PATH` is for task level metadata, which is used only for overriding the top level fields in the task metadata response. If you specify both `CONTAINER_METADATA_PATH` and `TASK_METADATA_PATH`, then the metadata from `CONTAINER_METADATA_PATH` will be included in the `Containers` section of the task metadata response. See example for overriding task metadata response [here](../example/generic).
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"Cluster": "arn:aws:ecs:us-west-2:ExampleAWSAccountNo1;:cluster/default",
3+
"TaskARN": "arn:aws:ecs:us-west-2:ExampleAWSAccountNo1;:task/default/febee046097849aba589d4435207c04a",
4+
"Family": "query-metadata",
5+
"Revision": "7",
6+
"DesiredStatus": "RUNNING",
7+
"KnownStatus": "RUNNING",
8+
"Limits": {
9+
"CPU": 0.25,
10+
"Memory": 512
11+
},
12+
"PullStartedAt": "2020-03-26T22:25:40.420726088Z",
13+
"PullStoppedAt": "2020-03-26T22:26:22.235177616Z",
14+
"AvailabilityZone": "us-west-2c"
15+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"Networks": [
3+
{
4+
"NetworkMode": "awsvpc",
5+
"IPv4Addresses": [
6+
"10.0.0.61"
7+
],
8+
"AttachmentIndex": 0,
9+
"IPv4SubnetCIDRBlock": "10.0.0.0/24",
10+
"MACAddress": "0a:d2:d0:80:b6:b4",
11+
"DomainNameServers": [
12+
"10.0.0.2"
13+
],
14+
"DomainNameSearchList": [
15+
"us-west-2.compute.internal"
16+
],
17+
"PrivateDNSName": "ip-10-0-0-61.us-west-2.compute.internal",
18+
"SubnetGatewayIpv4Address": ""
19+
}
20+
]
21+
}

0 commit comments

Comments
 (0)