Skip to content

Instantly share code, notes, and snippets.

@olsaki
Created August 17, 2016 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olsaki/53ced7fff4afb4e75183fc35b372366f to your computer and use it in GitHub Desktop.
Save olsaki/53ced7fff4afb4e75183fc35b372366f to your computer and use it in GitHub Desktop.
Get CloudFormation resources mapping from a stack with a specific parameter
import boto3
{ resource['LogicalResourceId']: resource['PhysicalResourceId'] for resource in boto3.client('cloudformation').describe_stack_resources(StackName=[ s[0] for s in [ (stack['StackName'], { parameter['ParameterKey']: parameter['ParameterValue'] for parameter in stack['Parameters'] } ) for stack in boto3.client('cloudformation').describe_stacks()['Stacks'] ] if 'MyParam' in s[1] and s[1]['MyParam'] == 'MyValue' ][0])['StackResources'] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment