gpt4 book ai didi

amazon-web-services - AWS 云形成堆栈中角色的托管策略

转载 作者:行者123 更新时间:2023-12-03 07:14:47 24 4
gpt4 key购买 nike

使用 AWS,我正在构建一个 cloud formation堆栈定义:

  1. 名为 MyPolicy 的托管策略
  2. 名为 MyRole 的角色,应附加该策略

堆栈将由管理员创建;创建后,目标是允许(从堆栈外部)一些用户承担 MyRole

我的问题:应如何定义角色才能附加该策略?


role properties 的 AWS 帮助页面建议使用 ManagedPolicyArns,但根据我引用 MyPolicy 的方式,我会收到各种错误:

如果我使用 GetAtt 函数检索策略的 arn,我会在模板验证时收到错误:

"ManagedPolicyArns": [ { "Fn::GetAtt" : [ "MyPolicy", "Arn" ] } ]

Template error: resource MyPolicy does not support attribute type Arn in Fn::GetAtt


如果我使用 Join 函数构建策略的 arn,我会在角色创建过程中收到错误。

"ManagedPolicyArns": [ { "Fn::Join" : [ "", [ "arn:aws:iam::", { "Ref": "AWS::AccountId" }, ":policy/", { "Ref": "MyPolicy" } ] ] } ]

ARN arn:aws:iam::aws:policy/arn:aws:iam::«my-account-id»:policy/MyPolicy is not valid. (Service: AmazonIdentityManagement; Status Code: 400; Error Code: InvalidInput; Request ID: «an-id»)


下面是我使用 JSON 格式的堆栈定义:

{
"AWSTemplateFormatVersion" : "2010-09-09",
"Resources" : {
"MyPolicy" : {
"Type": "AWS::IAM::ManagedPolicy",
"Properties": {
"ManagedPolicyName" : "MyPolicy",
"PolicyDocument" : {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [ "s3:*" ],
"Resource": "arn:aws:s3:::the-bucket"
}
]
}
}
},

"MyRole" : {
"Type": "AWS::IAM::Role",
"RoleName": "MyRole",
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "AWS": {"Fn::Join" : [ "", [ "arn:aws:iam::", { "Ref": "AWS::AccountId" }, ":root" ] ] } },,
"Action": [ "sts:AssumeRole" ]
}
]
},
"ManagedPolicyArns": [
{ "Fn::GetAtt" : [ "MyPolicy", "Arn" ] }
]
}
}
}

最佳答案

{"Ref": "MyPolicy"} 将返回您的堆栈创建的托管策略的 ARN。您的错误消息表明了这一点。另外,检查this AWS 文档。

关于amazon-web-services - AWS 云形成堆栈中角色的托管策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50795423/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com