gpt4 book ai didi

amazon-web-services - 在 Cloudformation 中使用 Fn::Sub 内的 Ref

转载 作者:行者123 更新时间:2023-12-04 15:29:51 25 4
gpt4 key购买 nike

我正在尝试使用其中包含 Ref 的 fn::sub

我有一个字符串“Comment xyz ${NAME}”。该字符串作为堆栈的参数。假设参数名称是“test”。

我现在想使用 Cloudformation 脚本中的 fn::sub 函数替换字符串中的 ${NAME}。

fn::sub:[{"Ref":"test"},{"NAME":"balaji"}]

预期输出是“Comment xyz balaji”。

但是,这是我收到的错误:

Template validation error: Template error: One or more Fn::Sub intrinsic functions don't specify expected arguments. Specify a string as first argument, and an optional second argument to specify a mapping of values to replace in the string

让我知道这里需要修复什么。

最佳答案

根据docsFn::Sub 中的第一个参数必须是:

A string with variables that AWS CloudFormation substitutes with their associated values at runtime. Write variables as ${MyVarName}. Variables can be template parameter names, resource logical IDs, resource attributes, or a variable in a key-value map. If you specify only template parameter names, resource logical IDs, and resource attributes, don't specify a key-value map.

(强调已添加。)

因此,(在撰写本文时)不可能做到这一点。

如果你有一个参数:

"test": {
"Type": "String",
"Default": "Comment xyz ${NAME}"
}

然后替换:

"Fn::Sub": ["${test}", {"NAME": "balaji"}]

替换将产生文字字符串Comment xyz ${NAME}

关于amazon-web-services - 在 Cloudformation 中使用 Fn::Sub 内的 Ref,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51379903/

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