Reputation: 876
Using the Join
function in CFN is driving me nuts.
It sometimes works and sometimes it doesn't and there seems to be nothing wrong with the sintaxes I'm using, the erros are not consistent. The validation of the template ALWAYS returns Ok but at the very last step of the stack creation, it fails, sometimes throwing an error while creating the resource (because of a badly formed name) or giving me this error message 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 there a good way of debuggin this instead of going all the way to creating the resources?
For instance, what is wrong with this syntax?
BucketName: !Join
- ''
- - !FindInMap
- Naming
- BasicPrefix
- Name
- '-'
- !Ref BusinessUnitName
- '-'
- !Ref EnvType
Or, why can't use a syntax like the one below for the same result?
BucketName: !Join
- '-'
- - !FindInMap
- Naming
- BasicPrefix
- Name
- !Ref BusinessUnitName
- !Ref EnvType
Or this shorthand one:
BucketName: !Join ['-', [!FindInMap [Naming, BasicPrefix, Name], !Ref BusinessUnitName, !Ref EnvType]]
None will work. I have to keep trying different ways of doing it, until CFN will accept it. It's exhausting.
Please help.
Upvotes: 1
Views: 939
Reputation: 6333
Your syntax looks correct but would require complete template to get to identify the cause for the error.
However for your scenario, Fn::Sub is much better option compared to Fn::Join, try using Fn::Sub with a mapping as below
BucketName: !Sub
- ${MapResult}-${BU}-${Env}
- { MapResult: !FindInMap [Naming, BasicPrefix, Name] }
- { BU: !Ref BusinessUnitName }
- { Env: !Ref EnvType }
Upvotes: 4