Can I use "Fn::Join" in "Parameters" of AWS Cloudformation json template

18,841

You cannot use intrinsic functions within the parameters section of your template.

You can use intrinsic functions only in specific parts of a template. Currently, you can use intrinsic functions in resource properties, metadata attributes, and update policy attributes.

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html

You will need use this function within your resource properties. For example:

"Parameters" : {
  "Env" : {
    "Type" : "String",
    "Default" : "test"
  },
  "WorkerName" : {
    "Type" : "String",
    "Default" : "my-worker"
  }
}

"Resources" : {
  "LoadBalancer" : {
    "Type" : "AWS::ElasticLoadBalancing::LoadBalancer",
    ...
    "Properties" : {
      "Tags" : [ 
        { "Key" : "Name", "Value": { "Fn::Join" : [ "-", [ "process", { "Ref" : "Env" }, { "Ref" : "SomeWorkerName" }]]}},
      ]
    }
  }
}

This will apply a 'Name' tag to your Load Balancer with a value of 'process-test-my-worker'. You can also use this same function anywhere else within the properties of your resources.

Share:
18,841

Related videos on Youtube

muzafarow
Author by

muzafarow

Updated on June 06, 2022

Comments

  • muzafarow
    muzafarow almost 2 years

    I want to use in Parameters of Cloudformation json template shortcut of some Policy/Loadbalancers tags name, like that:

    "SomeScalingGroupName": {
                "Type": "String",
                "Default": {"Fn::Join": ["", ["Process-", {"Ref": "Env"}, "-Some-Worker-Name"]]}
            },
    

    And I get error:

    Template validation error: Template format error: Every Default member must be a string.

    So my question if that proper way to use function join in Parameters? Or I they have any other way to do that? Or you have any better suggestions to using that?

    Thanks!

    • Mircea
      Mircea over 8 years
      the error tells you what is wrong. You cannot use a function (fn:join) for default values.
    • muzafarow
      muzafarow over 8 years
      @thext I don't see (fn:join) in error. Can you suggest how can I transform this peace of code for not getting error? Thanks!