amazon-web-services - 使用实例配置文件凭证的 AWS CLI

标签 amazon-web-services amazon-ec2 aws-cli

在 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/

相关文章:

amazon-web-services - s3 存储桶策略的策略 ID 有何作用?

amazon-web-services - 如何创建公共(public)多区域接入点策略?

php - 如何使用cli将项目上传到Amazon ECS

amazon-web-services - 如何使用 AWS CLI 删除 S3 存储桶中的多个文件

amazon-web-services - AWS CLI S3API在路径中找到最新文件夹

java - AWS Java SDK - AWS 身份验证需要有效的 Date 或 x-amz-date header

amazon-web-services - 如何在此 cloudformation 模板的 aws cli 命令中插入参数?

bash - 如何在CloudFormation中传入UserData作为参数

mysql - 为什么mysql select结果显示 "#REF!"而不是 "NULL"

json - 如何根据JMESPath中的两个条件选择数组中的元素?