In my template, I am passing a CommaDelimitedList
of account ids as a parameter.
I am hoping to do some Fn::Join
and/or Fn::Sub
magic to transform the list as follow:
"Accounts" : {
"Type" : "CommaDelimitedList",
"Default" : "12222234,23333334,1122143234,..."
}
To be used in the template as a list `root` ARN's as :
[
"arn:aws:iam::12222234:root"
"arn:aws:iam::23333334:root"
"arn:aws:iam::1122143234:root"
]
Right now I am passing in the full ARNs, so it's working, but it is kluncky. However the CFN built in functions are proving very hard at doing this.
Any one have ready code for something like this?
You use the Ref intrinsic function to reference a parameter, and AWS CloudFormation uses the parameter's value to provision the stack. You can reference parameters from the Resources and Outputs sections of the same template.
Pseudo parameters are parameters that are predefined by AWS CloudFormation. You don't declare them in your template. Use them the same way as you would a parameter, as the argument for the Ref function.
A collection of AWS resources is called a stack, and it can be managed in a single unit. CloudFormation's template defines a stack in which the resources can be created, deleted or updated in a predictable way. A stack can have all the resources (web server, database, etc.) required to run a web application.
To find a Stack ID, you can use either the Amazon EC2 console, AMS console, or the AMS SKMS API/CLI. AMS Console: In the navigation pane, select RFCs, and then click the RFC that created the stack. Use the filter option at the top to reduce the list.
I was able to adapt the existing answer by Sam Hammamy to work around the limitation of requiring special handling for the first and last items by using Fn::Sub
. You can also combine two of the Join
s.
In YAML:
AWS: !Split
- ','
- !Sub
- 'arn:aws:iam::${inner}:root'
- inner: !Join
- ':root,arn:aws:iam::'
- Ref: "Accounts"
And in JSON:
"Fn::Split": [
",",
{
"Fn::Sub": [
"arn:aws:iam::${rest}:root",
{
"rest": {
"Fn::Join": [
":root,arn:aws:iam::",
{ "Ref": "Accounts" }
]
}
}
]
}
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With