Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

Is there a straightforward way to access AWS instance metadata from within a Docker container?

For example, when trying to fetch credentials for an IAM role on an EC2 instance, this would work on the instance itself:

http://169.254.169.254/latest/meta-data/iam/security-credentials/my_role

...but not from within a Docker container running on that EC2 instance.

1 Answer

0 votes
by (44.4k points)

This container can be used to access EC2 metadata directly:

root@f1e5646e23:/# curl http://169.254.169.254/latest/meta-data/iam/security-credentials/myrole

{

  "Code" : "Success",

  "LastUpdated" : "2019-07-14T15:04:12Z",

  "Type" : "AWS-HMAC",

  "AccessKeyId" : "accesskey",

  "SecretAccessKey" : "secretkey",

  "Token" : "mytoken",

  "Expiration" : "2019-04-14T21:08:29Z"

}

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

Browse Categories

...