在 EC2 实例中使用 AWS CLI 时,如何指定要使用实例配置文件凭证?文档说:
Instance profile credentials – these credentials can be used on EC2
instances with an assigned instance role, and are delivered through
the Amazon EC2 metadata service.
这是自动的还是我需要调用元数据服务并将返回的凭证保存到 ~/.aws/credentials
文件...然后进行调用?
最佳答案
您正在谈论IAM Roles 。它们附加到 EC2 实例,并且 key 每四个小时滚动/轮换一次。
您不需要需要从实例元数据中提取这些内容并将其提供给 aws-cli 或 SDK,它们会自动提取它。
如果您使用 --debug
标志运行 aws-cli,您应该会看到凭证被拾取:
$ aws --debug s3 ls
...
2015-03-10 18:15:04,459 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: iam-role
2015-03-10 18:15:04,465 - MainThread - botocore.vendored.requests.packages.urllib3.connectionpool - INFO - Starting new HTTP connection (1): 169.254.169.254
2015-03-10 18:15:04,466 - MainThread - botocore.vendored.requests.packages.urllib3.connectionpool - DEBUG - "GET /latest/meta-data/iam/security-credentials/ HTTP/1.1" 200 37
2015-03-10 18:15:04,468 - MainThread - botocore.vendored.requests.packages.urllib3.connectionpool - INFO - Starting new HTTP connection (1): 169.254.169.254
2015-03-10 18:15:04,469 - MainThread - botocore.vendored.requests.packages.urllib3.connectionpool - DEBUG - "GET /latest/meta-data/iam/security-credentials/myrole-snipped HTTP/1.1" 200 898
2015-03-10 18:15:04,469 - MainThread - botocore.credentials - INFO - Found credentials from IAM Role: myrole-snipped
关于amazon-web-services - 使用实例配置文件凭证的 AWS CLI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28969719/