Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 316
muzafarow Avatar asked Dec 03 '15 09:12

muzafarow


People also ask

What is FN :: join in CloudFormation?

The intrinsic function Fn::Join appends a set of values into a single value, separated by the specified delimiter. If a delimiter is the empty string, the set of values are concatenated with no delimiter.

Which section of CloudFormation template does not allow for conditions?

According to the docs, Conditions should be used at the top level of the resource you want to conditionally create. Putting a Condition inside the Instance UserData section isn't supported. To use Conditions in your situation, you'd want separate Resources conditionally created based on the Parameter.

What part of a CloudFormation template allows you to pass values into the template?

Parameters (optional) Values to pass to your template at runtime (when you create or update a stack). You can refer to parameters from the Resources and Outputs sections of the template.

Which CloudFormation feature can be used in templates to assign values to properties that are not available until runtime?

Use intrinsic functions in your templates to assign values to properties that are not available until runtime. You can use intrinsic functions only in specific parts of a template. Currently, you can use intrinsic functions in resource properties, outputs, metadata attributes, and update policy attributes.


1 Answers

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.

like image 196
Jason Avatar answered Sep 29 '22 03:09

Jason