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" } } },
And here is an error I get:
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
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?
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}"}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With