gpt4 book ai didi

amazon-web-services - CFn : Use ! 如果要在语句中添加多个主体

转载 作者:行者123 更新时间:2023-12-05 03:30:18 28 4
gpt4 key购买 nike

我有以下定义 IAM 策略的模板,但该策略不起作用:

      RoleName: 'ABCRole'
AssumeRolePolicyDocument:
Statement:
- Action: ['sts:AssumeRole']
Effect: Allow
Principal:
AWS:
- 1234567890 # Some AWS account
- !If
- !And
- !Condition Condition1
- !Condition Condition2
- arn:aws:iam::11111111111111:role/ABCDE_Role # first role
- arn:aws:iam::22222222222222:role/ABCDE_Role # second role (different account number)
- !Ref AWS:NoValue

我正在尝试实现这一目标:当 Condition1Condition2 都为 true 时,我将能够附加 arn:aws:iam::11111111111111: role/ABCDE_Rolearn:aws:iam::22222222222222:role/ABCDE_Role 作为两个附加主体。否则,什么也不做——将 1234567890 作为唯一的主体。

请注意,arn:aws:iam::11111111111111:role/ABCDE_Rolearn:aws:iam::22222222222222:role/ABCDE_Role 仅与aws 帐户,所以也许我可以使用 !Sub 来替换帐号?有点像:

for account in [11111111111111, 22222222222222]:
!Sub arn:aws:iam::${account}:role/ABCDE_Role

我应该如何修改上面的模板?预先感谢您!

最佳答案

我认为是因为 !If 条件期望的格式,按照 aws 的文档,格式为:

!If [condition_name, value_if_true, value_if_false]

如果您检查模板,就会发现有四个元素,而不是三个。

此外,伪参数是(带有双:):

AWS::NoValue

因此,当条件为 True 时添加所需的两个帐户的可能解决方案可能是尝试添加一个新条件,将您已有的条件 1 和条件 2 与 !And 函数结合起来,如下所示:

Conditions:
Condition1: your condition
Condition2: your condition
ConditionCombined: !And [!Condition Condition1, !Condition Condition2]
Resources:
Role1:
Type: AWS::IAM::Role
Properties:
RoleName: 'ABCRole'
AssumeRolePolicyDocument:
Statement:
- Action: ['sts:AssumeRole']
Effect: Allow
Principal:
AWS:
- 1234567890 # Some AWS account
- !If
- ConditionCombined
- arn:aws:iam::11111111111111:role/ABCDE_Role # first role
- !Ref AWS::NoValue
- !If
- ConditionCombined
- arn:aws:iam::22222222222222:role/ABCDE_Role # second role (different account number)
- !Ref AWS::NoValue

关于amazon-web-services - CFn : Use ! 如果要在语句中添加多个主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70853987/

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