0 votes
1 view
in AWS by (16.7k 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 (39.6k 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"

}

...