Expose IMDS Client Command
- Dominant language
- Python
- Stars
- 17.3k
- Forks
- 4.6k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 13
Description
### Describe the feature
Expose a command for IMDS requests (e.g. `aws imds get --path /latest/user-data`) which automatically handles IMDS session token fetching + caching.
### Use Case
Shell scripts are often used to set up EC2 instances manually (e.g. via SSH or SSM sessions) or automatically (e.g. EC2 user data scripts, CodeDeploy Agent hooks, SSM documents). They are also used for simple on-instance EC2 Auto Scaling lifecycle hook daemons (e.g. systemd service units).
These may need to fetch data from IMDS (e.g. user data, auto scaling target lifecycle state).
Today, this requires using `curl` to manually fetch IMDS session tokens for use in subsequent get requests.
### Proposed Solution
The AWS SDKs implement an [IMDS client](https://docs.aws.amazon.com/sdkref/latest/guide/feature-imds-client.html). This is used to support IMDS region + credentials providers.
Some AWS SDKs expose the IMDS client to let users make IMDS calls without having to worry about fetching + caching session tokens. For example:
- [AWS SDK for Go v2](https://docs.aws.amazon.com/sdk-for-go/v2/developer-guide/sdk-utilities-ec2-imds.html)
- [AWS SDK for Java 2.x](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/examples-ec2-IMDS.html)
- [AWS SDK for Ruby v3](https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/EC2Metadata.html)
- [AWS SDK for Rust 0.x (via aws_config 1.x)](https://docs.rs/aws-config/latest/aws_config/imds/client/struct.Client.html)
The idea is to do the same for the AWS SDK for Python (boto) and the AWS CLI.
1. Update botocore to make the [`IMDSFetcher`](https://github.com/boto/botocore/blob/45da16d9d61d1610d57ed7e62d352364aa3e841b/botocore/utils.py#L369) or a similar class expose a general-purpose public `get()` method.
2. Add a CLI for the general-purpose public `get()` method.
> Tangent: Rather than manually write an IMDS client in all AWS SDKs, is there a Smithy (or its internal predecessor) model describing IMDS which can be fed into the Smithy code generators?
>
> This would probably need new Smithy auth and protocol traits like `aws.auth#imdsv2` and `aws.protocols#imds`.
>
> (cc: @mtdowling)
### Other Information
_No response_
### Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### CLI version used
2.*
### Environment details (OS name and version, etc.)
All
Contributor guide
Assessment
This issue has not been assessed yet.