Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine what CloudFormation stack an AWS resource belongs to?

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.

like image 251
kolanos Avatar asked Sep 22 '16 16:09

kolanos


People also ask

How do I find my stack name in CloudFormation?

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.

How do I find my AWS stack?

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.

How do you reference existing resources in CloudFormation?

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.

How do I find my AWS CloudFormation 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.


2 Answers

You can also use the AWS CLI to determine which stack a resource belongs to:

aws cloudformation describe-stack-resources --physical-resource-id "resourceId"

like image 74
Nik Rahmel Avatar answered Sep 22 '22 19:09

Nik Rahmel


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

like image 41
Czimi Avatar answered Sep 22 '22 19:09

Czimi