'CloudFormation: Is it possible to Fn::Join a CommaDelimitedList and a String?

I am currently having difficulty forming this statement correctly. I have been trying many variations and am confused why when I deploy, I am getting an error due to this statement(The deploy succeeds if I don't have this line)

Suppose I have a CommaDelimitedList called Fruits and a String called Banana

I currently have for my Cloudformation this line:

   "aws:PrincipalArn":{
   "Fn::Join":[",",[{"Ref":"Fruits"},"Ref":"Banana"}]]
   }

I have tried multiple variations for this code as well. I have tried doing a inner Fn::Join on Fruits to make it a string. I have also tried changing the typing of "Banana" to CommaDelimitedList.

All in all, I'm just lost at this point. Does anyone know the proper syntax in doing this or any ideas?



Solution 1:[1]

Since there are two different elements with 2 different data types, you should do it in 2 step process :

  • Perform !Join on the Fruits list to get Comma separated string.
  • Join two strings together with ","

Example:

"aws:PrincipalArn":{
    "Fn::Join":  [ "," , [ "Fn::Join":[",",[{"Ref":"Fruits"}] ], {"Ref":"Banana"}]]
    }

Solution 2:[2]

It should be:

"Fn::Join": [",", [ {"Fn::Join": [",", {"Ref": "Fruits"}]}, {"Ref":"Banana"}]]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nishu Tayal
Solution 2 Marcin