【发布时间】:2018-06-17 10:37:00
【问题描述】:
我正在尝试通过运行以下命令使用 AWS CLI 创建 CloudFormation 堆栈:
aws cloudformation create-stack --debug --stack-name ${stackName} --template-url ${s3TemplatePath} --parameters '${parameters}' --region eu-west-1
模板位于另一个账户的 S3 存储桶中,我们将此账户称为 456。存储桶策略:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Example permissions",
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::123:root"
]
},
"Action": [
"s3:*"
],
"Resource": "arn:aws:s3:::cloudformation.template.eberry.digital/*"
}
]
}
("Action: *" 用于调试)。
现在来个转折点。我已登录帐户 456 并运行
aws sts assume-role --role-arn arn:aws:iam::123:role/delegate-access-to-infrastructure-account-role --role-session-name jenkins
并设置正确的环境变量以访问 123。附加到我假设的角色的策略允许用户在我调试时 Administrator 访问 - 这仍然不起作用。
aws s3api list-buckets
然后显示帐户 123 中的存储桶。
总结一下:
- 在帐户 456 拥有的 S3 存储桶中指定模板到控制台中的 CloufFormation 中,同时登录帐户 123 有效。
- 使用 CLI 在账户 123 拥有的 S3 存储桶中指定模板可以正常工作。
- 使用 CLI 在帐户 456 拥有的 S3 存储桶中指定模板不起作用。
错误:
调用 CreateStack 操作时发生错误 (ValidationError):S3 错误:访问被拒绝 更多信息请查看http://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html
我不明白我做错了什么,并感谢任何想法。同时,我会将模板上传到所有将使用它的帐户。
【问题讨论】:
-
调用
aws sts assume-role ...并设置环境后。你能打电话给aws sts get-caller-identity证明你确实使用了临时权限吗? -
我不知道该命令,感谢您的提示。我不确定它是否证明我正在使用临时权限?然而,它们确实发生了变化。切换前返回的身份在456账号,切换后身份账号为123。
-
如果改变了,那么你做对了。你可以玩
aws s3 ls/aws s3 ls bucket_name- 也许这样会弹出一些东西...... -
我使用了
aws s3api head --bucket --key并能够从 CLI 获取文件的详细信息。尽管如此,在 --template-url 中引用它还是行不通的。 -
当然,
aws s3 ls从命令行更方便。好吧,它抱怨 S3 权限,并且您清楚地提供了管理员访问权限。看起来像错误。请报告错误 - forums.aws.amazon.com - 看过,但没有运气...
标签: amazon-web-services amazon-s3 amazon-cloudformation aws-cli