* Returns an array of all stacks that are related to some root stack through * nesting, including the root stack. The elements of the array are the objects * returned by describe-stacks. * @param {string} stackId * @returns {Promise }
(stackId)
| 33 | * @returns {Promise<Stack[]>} |
| 34 | */ |
| 35 | async function getStackHierarchy(stackId) { |
| 36 | const stackDesc = await cloudformation.describeStacks({ StackName: stackId }); |
| 37 | // Start with an array containing only the root stack |
| 38 | let stacks = stackDesc.Stacks; |
| 39 | |
| 40 | // Query all the resources in the given stack.. |
| 41 | const resourceList = await cloudformation.listStackResources({ |
| 42 | StackName: stackId, |
| 43 | }); |
| 44 | // ...and look for any child CloudFormation stacks |
| 45 | const resourceSummaries = resourceList.StackResourceSummaries; |
| 46 | const nestedStackSummaries = resourceSummaries.filter( |
| 47 | (r) => r.ResourceType === 'AWS::CloudFormation::Stack', |
| 48 | ); |
| 49 | |
| 50 | // Then recursively look for more descendents in those child stacks |
| 51 | for (const s of nestedStackSummaries) { |
| 52 | const nestedStackId = s.PhysicalResourceId; |
| 53 | const nestedStackFamily = await getStackHierarchy(nestedStackId); |
| 54 | stacks = stacks.concat(nestedStackFamily); |
| 55 | } |
| 56 | |
| 57 | return stacks; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Returns an object, where each key is the name of a parameter in Parameter |