Using Ref as the first argument in Fn::Sub intrinsic function

一世执手 提交于 2019-12-04 07:50:50

You cannot directly use a Ref within a Fn::Sub function call. To achieve a value mapping, you first have to assign the Ref value into a local variable und use that one within the Fn::Sub string.

"UserData": {
  "Fn::Base64": {
    "Fn::Sub": [
      "${variable}",
      {
        "variable": {
          "Ref": "myS3Bucket"
        }
      }]
  }
}

Alternatively it's possible to substitute directly without using a separate variable:

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

The key is to use Fn::Sub without the usual square brackets as explained at https://forums.aws.amazon.com/message.jspa?messageID=745085#745085

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.

The example given in the docs is:

{"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}"}

Or in context:

"UserData": {"Fn::Base64": {"Fn::Sub": "${UserDataParam}"}}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!