使用Ref作为Fn :: Sub内部函数中的第一个参数 [英] Using Ref as the first argument in Fn::Sub intrinsic function

查看:104
本文介绍了使用Ref作为Fn :: Sub内部函数中的第一个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在编译模板时遇到了很奇怪的问题,我在 Fn :: Sub 中引用一个字符串参数,而文档确实明确表示可以使用 Ref 函数位于 Fn :: Sub 中。这是一个模板:

I experience quite strange issues when compiling the template, where I reference a string parameter in Fn::Sub, while the docs do explicitly say that one can use Ref function inside of Fn::Sub. Here is a piece of template:

"Resources": {
    "LaunchConfiguration": {
      "Type" : "AWS::AutoScaling::LaunchConfiguration",
      "Properties" : {
        "UserData": { "Fn::Base64": { "Fn::Sub": { "Ref": "UserDataParam" } } },

这是我得到的错误:


模板错误:一个或多个Fn :: Sub内部函数未指定
预期参数。指定一个字符串作为第一个参数,并使用一个
可选的第二个参数来指定一个值映射,以替换
中的字符串

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

当我使用完整符号时: { Fn :: Sub:[{ Ref: UserDataParam},{}]} 同样的错误。有人遇到过同样的问题吗?

When I use full notation: { "Fn::Sub": [ { "Ref": "UserDataParam" }, {} ] }, I get exactly the same error. Has anybody had the same issue? And is it possible to avoid it while still using the parameter?

推荐答案

您正在误读文档。虽然文档确实说您可以使用 Ref 函数,但是只有在第二个(可选)参数(键值映射)中可以使用它。

You are misreading the docs. While the docs do say you can use the Ref function, it is only in the second (optional) parameter (the key-value map) where you can do that.

文档中给出的示例为:

{"Fn::Sub": ["www.${Domain}", {"Domain": {"Ref": "RootDomainName"}}]}

但是,如果需要将其替换为第一个参数,则必须使用美元符号。

If, however, you need to substitute into the first parameter, you must use the dollar notation.

要实现所显示的效果如果需要,您应该将代码重写为:

To achieve what you appear to want, you should rewrite your code as:

{"Fn::Sub": "${UserDataParam}"}

或在上下文中:

"UserData": {"Fn::Base64": {"Fn::Sub": "${UserDataParam}"}}

这篇关于使用Ref作为Fn :: Sub内部函数中的第一个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆