aws-sdk-ruby icon indicating copy to clipboard operation
aws-sdk-ruby copied to clipboard

Add ECS Task Metadata client

Open mdomsch-seczetta opened this issue 1 year ago • 1 comments

Describe the feature

Similar to the existing Aws::EC2Metadata client class, it would be helpful to have a metadata client class that retrieves and presents data from the ECS Task Metadata endpoint described here: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v4.html

While I could retrieve the response from the ECS Task Metadata endpoint and parse the Cluster field from it, having a built-in method to retrieve this would be simpler and cleaner, and is in keeping with how I get the EC2 instance ID already.

Use Case

I want to use this client class to let an application running in ECS on EC2 retrieve the name of the ECS Cluster name it is a part of, for use when calling UpdateContainerInstancesState https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_UpdateContainerInstancesState.html . This method requires passing in the cluster name, as well as the EC2 instance ID, to set the status to a value. I want to set the status to DRAINING to prevent ECS from placing a task on an EC2 instance that is in one of the Terminating states, but ECS is not aware of this. Because I can control when an EC2 instance is put into a Terminating state, I can also put the ECS container instance state to DRAINING at the same time.

Proposed Solution

Implement similar to the Aws::EC2Metadata client class.

Other Information

No response

Acknowledgements

  • [ ] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

SDK version used

3.165.0

Environment details (OS name and version, etc.)

Ruby 3.1.2 on Linux, e.g. ruby:3.1.2-slim-bullseye from docker hub

mdomsch-seczetta avatar Jan 06 '23 03:01 mdomsch-seczetta

Thanks for opening up a feature request. I do think this is a valid feature request for SDKs, but I am unsure on timeline of delivery and priority. I will share this with the organization.

mullermp avatar Jan 06 '23 16:01 mullermp

It's worth mentioning that the current classes use the V2 Endpoint which is no longer maintained:

Screenshot 2024-03-21 at 12 06 07 PM

The endpoint still either defaults to - or is hardcoded to - 169.254.170.2 at multiple points in the SDK:

Screenshot 2024-03-21 at 12 04 32 PM

This should be refactored to use the V4 endpoint. I have encountered an issue in the last few days where the client can't connect to 169.254.170.2 for some containers.

tomdionysus avatar Mar 20 '24 23:03 tomdionysus

This feature request is for a metadata client, similar to EC2Metadata that we provide in the SDK. The classes above are for credentials and are not supposed to hardcode a versioned endpoint. Neither of the V2 or V4 documentation linked mention usage for credentials fetching.

ECSCredentials should look at AWS_CONTAINER_CREDENTIALS_FULL_URI or AWS_CONTAINER_CREDENTIALS_RELATIVE_URI environment variables and those URIs may already have a v4 path.

mullermp avatar Mar 21 '24 14:03 mullermp