我一直在尝试使用YAML格式编写我的一些AWS CloudFormation模板。
然而,在使用替换变量时,例如${aws:username}
,CloudFormation会出现解析IAM策略变量的问题。以下是一个例子:
CommonUserGroup:
Type: AWS::IAM::Group
Properties:
GroupName: Common
Path: /project/
Policies:
- PolicyName: ClusterPolicy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: "iam:GetAccountPasswordPolicy"
Resource: "*"
- Effect: Allow
Action: "iam:ChangePassword"
Resource: !Sub 'arn:aws:iam::${AWS::AccountId}:user/${aws:username}'
当使用CloudFormation模板尝试创建堆栈时,将返回以下错误:
Template validation error: Template format error: Unresolved resource dependencies [aws:username] in the Resources block of the template
如果我手动指定用户名,而不是使用策略变量,例如:
'arn:aws:iam::${AWS::AccountId}:user/bob'
然后错误就会消失。
有没有一种方法可以转义策略变量,使得CloudFormation不会将它们作为模板的一部分进行解析?