gpt4 book ai didi

amazon-web-services - 引用 CloudFormation 中的 GroupName

转载 作者:行者123 更新时间:2023-12-03 07:29:09 25 4
gpt4 key购买 nike

在具有资源的 CFT 中 - IAM 策略中引用变量组名称的“GroupNamed”

 GroupNamed:
Type: "AWS::IAM::Group"
Properties:
GroupName: xyz

...

Effect: Allow
Action: iam:AddUserToGroup
Resource: !Sub arn:aws:iam::${AWS::AccountId}:group/GroupNamed

如何参数化组名称?

以下是我的尝试,但抛出了格式错误的策略错误。

1.

Resource: !Join ["", ['arn:aws:iam::',!Sub ${AWS::AccountId}, ':group/',!Ref GroupNamed]]

2.

Resource: !Join ["", ['arn:aws:iam::', !Ref AWS::AccountId, ':group/', !Ref GroupNamed]]

3.

Resource:
Fn::Join:
- ''
- - 'arn:aws:iam::'
- Fn::Sub: "${AWS::AccountId}"
- ":group/"
- Fn::Ref: GroupNamed

Error: Template validation error: Template Error: Encountered unsupported function: Fn::Ref Supported functions are: [Fn::Base64, Fn::GetAtt, Fn::GetAZs, Fn::ImportValue, Fn::Join, Fn::Split, Fn::FindInMap, Fn::Select, Ref, Fn::Equals, Fn::If, Fn::Not, Condition, Fn::And, Fn::Or, Fn::Contains, Fn::EachMemberEquals, Fn::EachMemberIn, Fn::ValueOf, Fn::ValueOfAll, Fn::RefAll, Fn::Sub, Fn::Cidr]

最佳答案

AWS::IAM::Group documentation 表示 ARN 可通过 GetAtt 获得。

例如,这会输出组的 ARN:

---
AWSTemplateFormatVersion: 2010-09-09
Description: CloudFormation template for creating lab resources.

Resources:

GroupNamed:
Type: "AWS::IAM::Group"
Properties:
GroupName: xyz

Outputs:
GroupARN:
Value: !GetAtt GroupNamed.Arn

输出为:arn:aws:iam::123456789012:group/xyz

因此,您可以使用:

Resource: !GetAtt GroupNamed.Arn

关于amazon-web-services - 引用 CloudFormation 中的 GroupName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50900045/

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