Is there a reliable way in boto3 to determine what CloudFormation stack an AWS resource belongs to? Or if it belongs to a stack at all? Say I have a DynamoDB table or an EC2 instance, how do I find out what stack it is a member of? The boto3 API for CloudFormation gets pretty vague at the resource level, or so it appears. Any help is much appreciated.
A stack name can contain only alphanumeric characters (case-sensitive) and hyphens. It must start with an alphabetic character and can't be longer than 128 characters. In the Parameters section, specify parameters that are defined in the stack template. You can use or change any parameters with default values.
To view information about your CloudFormation stackOn the Stacks page of the CloudFormation console, select the stack name. CloudFormation displays the stack details for the selected stack. Select a stack details pane to view the related information about your stack.
To import existing resources into a CloudFormation stack, you need to provide: A template that describes the entire stack, including both the resources to import and (for existing stacks) the resources that are already part of the stack. Each resource to import must have a DeletionPolicy attribute in the template.
To check your template file for syntax errors, you can use the aws cloudformation validate-template command. The aws cloudformation validate-template command is designed to check only the syntax of your template.
You can also use the AWS CLI to determine which stack a resource belongs to:
aws cloudformation describe-stack-resources --physical-resource-id "resourceId"
You can pass PhysicalResourceId
of a resource to desribe_stack_resources
and get the stack information if it belongs to a CF stack
To find an EC2 host for example
cf = boto3.client('cloudformation')
cf.describe_stack_resources(PhysicalResourceId="i-07bd92638b049ccc4")
AWS Documentation on this http://boto3.readthedocs.io/en/latest/reference/services/cloudformation.html#CloudFormation.Client.describe_stack_resources
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