如何转义“ $ {}”在云形式“ Fn :: Sub”中 [英] How to escape "${}" in cloudformations "Fn::Sub"
问题描述
我希望此资源与!Sub
(或 Fn :: Sub
)内在函数一起使用
I want this resource to work with the !Sub
(or Fn::Sub
) intrinsic function
Resource: !Sub 'arn:aws:iam::${AWS::AccountId}:user/${aws:username}'
aws:username
是<不能替换的href = http://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_variables.html rel = noreferrer>政策变量。
一种解决方案是改用 Fn :: Join
并编写更多样板代码。
One solution would be to use Fn::Join
instead and write a bit more boilerplate code.
更好:您可以逃避 $ {aws:username}
以便!Sub
在这里可以用吗? 不幸的是,文档
Better: Can you escape the ${aws:username}
so that !Sub
will work here? Unfortunately, the documentation does not mention anything about escaping.
推荐答案
实际上,您可以使用 $ {!}来转义 $字符。 。
You actually can escape "$" characters with "${!}".
因此您的资源应如下所示:
So your resource would look like this:
Resource: !Sub 'arn:aws:iam::${AWS::AccountId}:user/${!aws:username}'
文档在字符串参数部分。
要从字面上写一个美元符号和花括号($ {}),在大括号后加上
感叹号(!),例如$ {!Literal}。
AWS CloudFormation将此文本解析为$ {Literal}。
To write a dollar sign and curly braces (${}) literally, add an exclamation point (!) after the open curly brace, such as ${!Literal}. AWS CloudFormation resolves this text as ${Literal}.
这篇关于如何转义“ $ {}”在云形式“ Fn :: Sub”中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!