Skip to content

Conversation

@q2ven
Copy link
Contributor

@q2ven q2ven commented Apr 7, 2025

Issue #, if available:

No issue created.

Description of changes:

ec2-metadata does not support all meta-data listed in the document. [0]

Let's support such meta-data with a generic option, --path.

It can be specified multiple times and used with other options:

  $ ./ec2-metadata --path events/maintenance/scheduled \
    --path meta-data/identity-credentials/ec2/security-credentials/ec2-instance \
    --region
  latest/meta-data/events/maintenance/scheduled: []
  latest/meta-data/identity-credentials/ec2/security-credentials/ec2-instance: {
    "Code" : "Success",
    "LastUpdated" : "2025-04-07T04:58:06Z",
    "Type" : "AWS-HMAC",
    ...
    "Expiration" : "2025-04-07T11:01:19Z"
  }
  region: ap-northeast-1

Also, it can be used to fetch non-latest meta-data and dynamic data:

  $ ./ec2-metadata --path /
  /: 1.0
  2007-01-19
  ...

  $ ./ec2-metadata --path /2009-04-04/dynamic
  /2009-04-04/dynamic: instance-identity/

Link: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html #[0]

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@q2ven q2ven force-pushed the arbitrary_path branch 2 times, most recently from 891e42c to 338572b Compare April 7, 2025 06:18
@joeysk2012
Copy link

Looks good to me.

ec2-metadata does not support all meta-data listed in the document. [0]

Let's support such meta-data with a generic option, --path.

It can be specified multiple times and used with other options:

  $ ./ec2-metadata --path events/maintenance/scheduled \
    --path meta-data/identity-credentials/ec2/security-credentials/ec2-instance \
    --region
  latest/meta-data/events/maintenance/scheduled: []
  latest/meta-data/identity-credentials/ec2/security-credentials/ec2-instance: {
    "Code" : "Success",
    "LastUpdated" : "2025-04-07T04:58:06Z",
    "Type" : "AWS-HMAC",
    ...
    "Expiration" : "2025-04-07T11:01:19Z"
  }
  region: ap-northeast-1

Also, it can be used to fetch non-latest meta-data and dynamic data:

  $ ./ec2-metadata --path /
  /: 1.0
  2007-01-19
  ...

  $ ./ec2-metadata --path /2009-04-04/dynamic
  /2009-04-04/dynamic: instance-identity/

Link: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html #[0]
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
@q2ven q2ven force-pushed the arbitrary_path branch from 338572b to a4133d3 Compare May 10, 2025 00:05
@joeysk2012 joeysk2012 merged commit 87b7df1 into amazonlinux:main May 10, 2025
1 check passed
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.

3 participants