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

I am having rather strange problems compiling a template when I refer to the string parameter in Fn::Sub, while the documents directly say that you can use the function Refinside Fn::Sub. Here is a piece of the template:

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

And here is the error I get:

Template error: one or more of the built-in Fn :: Sub functions does not indicate the expected arguments. Specify a string as the first argument and an optional second argument to specify a mapping of values ​​to replace in the string

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

+6
3

Ref Fn:: Sub. , Ref Fn:: Sub.

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

:

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

Fn::Sub , https://forums.aws.amazon.com/message.jspa?messageID=745085#745085

0

You are reading documents incorrectly. Although the documents say that you can use the function Ref, only in the second (optional) parameter (key-value map) can you do this.

Example provided in the documentation:

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

However, if you need to substitute the first parameter, you must use dollar notation.

To achieve what you want, you must rewrite the code as follows:

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

Or in context:

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

Source: https://habr.com/ru/post/1665560/


All Articles