gpt4 book ai didi

aws-cloudformation - 如何在cloudformations "${}"中转义 "Fn::Sub"

转载 作者:行者123 更新时间:2023-12-03 11:35:10 26 4
gpt4 key购买 nike

我希望此资源与 !Sub (或 Fn::Sub)内部函数一起使用

Resource: !Sub 'arn:aws:iam::${AWS::AccountId}:user/${aws:username}'

aws:usernamepolicy variable不得更换。

一种解决方案是使用 Fn::Join 并编写更多样板代码。

更好:您可以转义 ${aws:username} 以便 !Sub 在这里工作吗? 不幸的是, documentation没有提到任何关于逃跑的事情。

最佳答案

实际上,您可以使用 ${!} 转义 $ 字符。

因此您的资源将如下所示:

Resource: !Sub 'arn:aws:iam::${AWS::AccountId}:user/${!aws:username}'

docs中提到在字符串参数部分下。

To write a dollar sign and curly braces (${}) literally, add anexclamation point (!) after the open curly brace, such as ${!Literal}.AWS CloudFormation resolves this text as ${Literal}.

关于aws-cloudformation - 如何在cloudformations "${}"中转义 "Fn::Sub",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44458304/

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