amazon-web-services - 通过 AWS CLI 使用临时安全凭证
问题描述
我想在 AWS CLI 中生成临时凭证,我知道应该使用以下命令。
$ aws sts assume-role --role-arn arn:aws:iam::123456789012:role/role-name --role-session-name "RoleSession1" --profile IAM-user-name > assume-role-output.txt
我还随身带着访问密钥和密钥。
我也跑了aws sts get-caller-identity
,得到:
{
"Account": "12345",
"UserId": "AIXXXXXXXNUNHY",
"Arn": "arn:aws:iam::12345:user/dcp/ua.166666654"
}
但我不明白我应该在上述命令中替换哪些值来获取临时凭据。
解决方案
您的调用assume-role
将返回类似于以下内容的信息:
{
"AssumedRoleUser": {
"AssumedRoleId": "AROAxx:RoleSession1",
"Arn": "arn:aws:sts::123456789012:assumed-role/role/role-name"
},
"Credentials": {
"SecretAccessKey": "xxx",
"SessionToken": "xxx",
"Expiration": "2018-11-13T07:50:29Z",
"AccessKeyId": "ASIAxxx"
}
}
然后,运行:
aws configure --profile RoleSession1
并输入assume-role
(Access Key, Secret Key, Token) 提供的详细信息。
这会将新凭据存储在标题.aws/credentials
下的文件中。[RoleSession1]
要使用这些凭据,请指定您刚刚定义的配置文件:
aws s3 ls --profile RoleSession1
推荐阅读
- python-3.x - 如何使用python检查用户是否存在
- ios - 如何将 CMSampleBufferRef 转换为 UIIMage
- php - 向嵌套字段添加属性
- jquery - 使用 jQuery.Validate 显示正确的面板
- push-notification - 代号一推送通知失败
- powershell - 使用 .txt 文件填充 Powershell 脚本
- javascript - 如何使用 Vue 对全局变量做出反应?
- raku - 模块名称匹配
- json - 将 JSON 对象分配给 ReactJS 中的样式属性是否会使对象不可配置
- amazon-s3 - 是否可以在 fluentd s3_output 中设置主机