Using a function to provide Fn::Join's delimiter?

1,192 views
Skip to first unread message

Amos S

unread,
Apr 19, 2015, 7:15:46 PM4/19/15
to cloudto...@googlegroups.com
I'm trying to parametise the delimiter used by an Fn::Join, e.g. at first I had:

"Name" : { "Fn::Join" : [ ".", [ 
               { "Ref":"serviceName"}, { "Ref": "environment" } ] ] },

Which works well, but then I changed it to:

"Name" : { "Fn::Join" : [ {"Ref":"HostNameSeparator"}, [
               { "Ref":"serviceName"}, { "Ref": "environment" } ] ] },

I get the following error from the validation phase:

A client error (ValidationError) occurred when calling the
    ValidateTemplate operation: Template error: every Fn::Join object
    requires two parameters, (1) a string delimiter and (2) a list of
    strings to be joined or a function that returns a list of strings
    (such as Fn::GetAZs) to be joined.

Is it possible to do what I want, i.e. pass the Join delimiter as a template parameter?

(I've shortened the examples above for clarity sake, please ignore typos)

As a work-around, I calculate the join in the script which calls the cloudformation creation command
and pass the final value as a parameter, but it's not ideal since it means that I repeat the input to the template
more than once (the "serviceName" and "environment" parameters above, for instance).

Michael Barrett

unread,
Apr 22, 2015, 12:21:02 AM4/22/15
to Amos S, cloudto...@googlegroups.com
Hey Amos - I'm trying to reproduce this.  Can you tell me what sort of resource you are applying this to?

--
You received this message because you are subscribed to the Google Groups "cloudtools-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cloudtools-de...@googlegroups.com.
To post to this group, send email to cloudto...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cloudtools-dev/67cd015f-5e53-4273-8b99-6678613e9129%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Barrett

unread,
Apr 22, 2015, 12:24:10 AM4/22/15
to Amos S, cloudto...@googlegroups.com
Actually - another question - how are you writing the template?  Are you using troposphere, or are you creating the JSON Template by hand and then trying to do something with it?

Amos S

unread,
Apr 22, 2015, 12:39:21 AM4/22/15
to cloudto...@googlegroups.com, amos.s...@gmail.com
I'm (trying to) use it to set the "Name" property of an AWS::Route53::RecordSet resource.
This is what the resource would look like if the Fn::Join worked:

        "LoadBalancerDNSRecord" : {
            "Type" : "AWS::Route53::RecordSet",
            "Condition" : "UpdateDNS",
            "Properties" : {
                "HostedZoneId" : "/hostedzone/Z25PF77UMQRIWR",
                "Comment" : "CNAME for ELB",
                "Name" : { "Fn::Join" : [ {"Ref":"HostNameSeparator"}, [
                         { "Ref":"serviceName"}, { "Ref": "environment" } ] ] },
                "Type" : "CNAME",
                "TTL" : "900",
                "ResourceRecords" : [
                    {"Fn::GetAtt":["LoadBalancer","DNSName"]}
                ]
            }
        },

Amos S

unread,
Apr 22, 2015, 12:40:40 AM4/22/15
to cloudto...@googlegroups.com, amos.s...@gmail.com
For now I maintain the template JSON file by hand using a text editor.

Michael Barrett

unread,
Apr 22, 2015, 12:46:44 AM4/22/15
to Amos S, cloudto...@googlegroups.com
In the version that you maintain by hand in JSON, do you have any issues using Join & Ref's for the parts & separator, or is that only an issue when you try to do the same in troposphere?

Amos S

unread,
Apr 22, 2015, 12:51:10 AM4/22/15
to cloudto...@googlegroups.com, amos.s...@gmail.com
I'm sorry I didn't realise that this group is about Troposphere. I was referred here by someone after I didn't get responses on the AWS support forums.
I don't use troposphere.
Back to your latest question - the issue happens using the static JSON file. I don't use Troposphere and haven't heard about it until now.

Michael Barrett

unread,
Apr 22, 2015, 12:54:19 AM4/22/15
to Amos S, cloudto...@googlegroups.com
Oh, yeah, then in this case it's likely that it's not possible if you're writing it in plain CloudFormation templates and it's throwing a Validation error.  

Amos S

unread,
Apr 22, 2015, 12:57:20 AM4/22/15
to cloudto...@googlegroups.com, amos.s...@gmail.com
Thanks for the confirmation.
Reply all
Reply to author
Forward
0 new messages