AWS CLI CloudFormation anecdote (why you no filter list-stacks?)
The commonality for ANYone trying to do this, is the "TemplateDescription" == "(SO0044) - AWS Landing Zone Initiation Template". Cool, I'll just run an "aws cloudformation list-stacks"... select the key fields, run a filter
... oh... wait.. you CAN'T apply a filter to this output. :-( The only filter capability that the "cloudformation" option has is for "status".
At some point I hope to "the answer", but I want to document my attempt at creating a solution along the way.
Here is a command to get some useful output...
$ aws cloudformation list-stacks --region=us-east-1 --query "StackSummaries[].[StackName, TemplateDescription]" --output text
Now... the trouble with this command, it will produce 2 outputs... what if the StackName has spaces. Well, as it turns out, a StackName will *NOT* have spaces.
"Stack name must contain only letters, numbers, dashes. Must start with a letter."
That nuance actually makes this problem a bit easier.
$ REGION=us-east-1
$ STACKNAME=$(aws cloudformation list-stacks --region=us-east-1 --query "StackSummaries[].[StackName, TemplateDescription]" --output text | grep "(SO0044) - AWS Landing Zone Initiation Template" | awk '{ print $1 }')
$ LZVERSION=$(aws cloudformation describe-stacks --region=${REGION} --stack-name=${STACKNAME} --query "Stacks[*].Outputs[*]" | grep -B2 -A2 "Version Number" | grep "OutputValue")
$ echo $LZVERSION
... oh... wait.. you CAN'T apply a filter to this output. :-( The only filter capability that the "cloudformation" option has is for "status".
At some point I hope to "the answer", but I want to document my attempt at creating a solution along the way.
Here is a command to get some useful output...
$ aws cloudformation list-stacks --region=us-east-1 --query "StackSummaries[].[StackName, TemplateDescription]" --output text
Now... the trouble with this command, it will produce 2 outputs... what if the StackName has spaces. Well, as it turns out, a StackName will *NOT* have spaces.
"Stack name must contain only letters, numbers, dashes. Must start with a letter."
That nuance actually makes this problem a bit easier.
$ REGION=us-east-1
$ STACKNAME=$(aws cloudformation list-stacks --region=us-east-1 --query "StackSummaries[].[StackName, TemplateDescription]" --output text | grep "(SO0044) - AWS Landing Zone Initiation Template" | awk '{ print $1 }')
$ LZVERSION=$(aws cloudformation describe-stacks --region=${REGION} --stack-name=${STACKNAME} --query "Stacks[*].Outputs[*]" | grep -B2 -A2 "Version Number" | grep "OutputValue")
$ echo $LZVERSION
Comments
Post a Comment