如何转义“${}"在 cloudformations “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
是一个 政策不能被替换的变量.
一种解决方案是改用 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}'
文档 在字符串参数部分下.
It is mentioned in the docs under the string parameter section.
要从字面上写一个美元符号和花括号 (${}),请添加一个左花括号后的感叹号 (!),例如 ${!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}.
这篇关于如何转义“${}"在 cloudformations “Fn::Sub"中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!