I want this resource to work with the !Sub
(or Fn::Sub
) intrinsic function
Resource: !Sub 'arn:aws:iam::${AWS::AccountId}:user/${aws:username}'
The aws:username
is a pollicy variable that mustn't be replaced.
One solution would be to use Fn::Join
instead and write a bit more boilerplate code.
Better: Can you escape the ${aws:username}
so that !Sub
will work here? Unfortunately, the documentation does not mention anything about escaping.
答案 0 :(得分:26)
您实际上可以使用“$ {!}”转义“$”字符。
所以你的资源看起来像这样:
Resource: !Sub 'arn:aws:iam::${AWS::AccountId}:user/${!aws:username}'
在字符串参数部分的docs中提到。
按字面意思写一个美元符号和花括号($ {}),添加一个 打开花括号后的感叹号(!),例如$ {!Literal}。 AWS CloudFormation将此文本解析为$ {Literal}。