Skip to content

Conversation

singholt
Copy link
Contributor

@singholt singholt commented Aug 20, 2025

Summary

The ECS agent provides a task metadata endpoint - /taskWithTags. Containers belonging to an ECS task can query this endpoint to retrieve task and container instance tags. The ECS agent makes ECS ListTagsForResource API calls on behalf of the containers querying the metadata endpoint.

Querying this TMDS endpoint and making the ECS API requests too frequently can lead to API throttling. Often, customers use services like AWS CloudTrail to debug operational issues like throttling. Additionally, ECS operators/oncalls also benefit from this change by identifying the name of the container in the API request header.

This PR enables tracing HTTP requests from containers to specific ECS ListTagsForResource API calls in CloudTrail, improving observability and debugging capabilities.

Implementation details

Changes:

  • Add ContainerNameByV3EndpointID method to TaskEngineState interface
  • Modify NewTaskResponse to accept v3EndpointID and pass container name to context
  • Update GetResourceTags to accept context parameter for container identification
  • Enhance ecsRoundTripper.userAgent to append container name from request context
  • Update TMDS v4 handler to pass endpoint ID through call chain
  • Add comprehensive unit tests for new functionality

Testing

New tests cover the changes: yes

Tested manually and verified CloudTrail logs.

Before

"eventSource": "ecs.amazonaws.com",
"eventName": "ListTagsForResource",

...
...

"userAgent": "Amazon ECS Agent - v1.98.0 (6e9b8f38) (linux; amzn_2023) (+http://aws.amazon.com/ecs/)"

After

"eventSource": "ecs.amazonaws.com",
"eventName": "ListTagsForResource",

...
...

"userAgent": "Amazon ECS Agent - v1.98.0 (d3ca4e53) (linux; amzn_2023) (+http://aws.amazon.com/ecs/) container/sample-app"

Description for the changelog

Enhancement: Add container name visibility to the ListTagsForResource CloudTrail events coming from ECS agent

Additional Information

Does this PR include breaking model changes? If so, Have you added transformation functions? no

Does this PR include the addition of new environment variables in the README? no

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@singholt singholt force-pushed the dev branch 7 times, most recently from 50432e6 to 0532b7b Compare August 21, 2025 16:37
@singholt singholt changed the title Add container name to ECS ListTagsForResource HTTP requests Add container name to ECS ListTagsForResource request headers Aug 21, 2025
@singholt singholt force-pushed the dev branch 10 times, most recently from d5a8646 to d3ca4e5 Compare August 21, 2025 18:54
@singholt singholt marked this pull request as ready for review August 21, 2025 23:20
@singholt singholt requested a review from a team as a code owner August 21, 2025 23:20
ShelbyZ
ShelbyZ previously approved these changes Aug 25, 2025
@singholt singholt enabled auto-merge (rebase) August 25, 2025 20:01
Enhance CloudTrail visibility by including container name in HTTP User-Agent
header when ECS agent makes ListTagsForResource API calls on behalf of containers.

Changes:
- Add ContainerNameByV3EndpointID method to TaskEngineState interface
- Modify NewTaskResponse to accept v3EndpointID and pass container name to context
- Update GetResourceTags to accept context parameter for container identification
- Enhance ecsRoundTripper.userAgent to append container name from request context
- Update TMDS v4 handler to pass endpoint ID through call chain
- Add comprehensive unit tests for new functionality

This enables tracing HTTP requests from containers to specific ECS API calls
in CloudTrail logs, improving observability and debugging capabilities.
@singholt singholt enabled auto-merge (rebase) August 25, 2025 22:49
@singholt singholt merged commit b71285b into aws:dev Aug 26, 2025
40 checks passed
@danehlim danehlim mentioned this pull request Sep 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants