描述嵌套 CloudFormation 堆栈资源的正确方法是啥?

Posted

技术标签:

【中文标题】描述嵌套 CloudFormation 堆栈资源的正确方法是啥?【英文标题】:What is the proper way to describe resources of a nested CloudFormation stack?描述嵌套 CloudFormation 堆栈资源的正确方法是什么? 【发布时间】:2017-01-16 21:23:01 【问题描述】:

我们有一个 CloudFormation 脚本,它有四个嵌套堆栈。我试图描述那些嵌套堆栈的资源。但是,当我 describe-stack-resources 使用其中一个嵌套堆栈的物理 ID 时,它只返回“父”堆栈(谁的资源只是嵌套堆栈)。此行为在 javascript 开发工具包和 AWS CLI 中是一致的。

我这样做对吗?这是一个错误吗?有解决办法吗?

AWS CLI 请求示例:

(注意:请求的物理资源ID是返回的第二个)

aws cloudformation describe-stack-resources --physical-resource-id arn:aws:cloudformation:us-west-2:58701038XXXX:stack/pelorus-vk-DatabaseStack-W12E3SAXPG6K/b0197770-7519-11e6-9518-50aXXXXXca9a

    "StackResources": [
        
            "StackId": "arn:aws:cloudformation:us-west-2:58701038XXXX:stack/pelorus-vk/f93b5960-7518-11e6-8939-XXXXX0f2ad1e",
            "ResourceStatus": "UPDATE_COMPLETE",
            "ResourceType": "AWS::CloudFormation::Stack",
            "Timestamp": "2016-09-07T16:53:11.305Z",
            "StackName": "pelorus-vk",
            "PhysicalResourceId": "arn:aws:cloudformation:us-west-2:58701038XXXX:stack/pelorus-vk-DashboardStack-1GDLBCAFE6U3F/fb9c53d0-7518-11e6-bd48-50dXXXXX84d2",
            "LogicalResourceId": "DashboardStack"
        ,
        
            "StackId": "arn:aws:cloudformation:us-west-2:58701038XXXX:stack/pelorus-vk/f93b5960-7518-11e6-8939-XXXXX0f2ad1e",
            "ResourceStatus": "CREATE_COMPLETE",
            "ResourceType": "AWS::CloudFormation::Stack",
            "Timestamp": "2016-09-07T16:53:04.667Z",
            "StackName": "pelorus-vk",
            "PhysicalResourceId": "arn:aws:cloudformation:us-west-2:58701038XXXX:stack/pelorus-vk-DatabaseStack-W12E3SAXPG6K/b0197770-7519-11e6-9518-50aXXXXXca9a",
            "LogicalResourceId": "DatabaseStack"
        ,
        
            "StackId": "arn:aws:cloudformation:us-west-2:58701038XXXX:stack/pelorus-vk/f93b5960-7518-11e6-8939-XXXXX0f2ad1e",
            "ResourceStatus": "UPDATE_COMPLETE",
            "ResourceType": "AWS::CloudFormation::Stack",
            "Timestamp": "2016-09-07T16:53:13.293Z",
            "StackName": "pelorus-vk",
            "PhysicalResourceId": "arn:aws:cloudformation:us-west-2:58701038XXXX:stack/pelorus-vk-EventProcessingStack-GB814FASNNV4/fb8f3470-7518-11e6-a2c5-503XXXXXadae",
            "LogicalResourceId": "EventProcessingStack"
        ,
        
            "StackId": "arn:aws:cloudformation:us-west-2:587010381366:stack/pelorus-vk/f93b5960-7518-11e6-8939-XXXXX0f2ad1e",
            "ResourceStatus": "UPDATE_COMPLETE",
            "ResourceType": "AWS::CloudFormation::Stack",
            "Timestamp": "2016-09-07T16:53:11.496Z",
            "StackName": "pelorus-vk",
            "PhysicalResourceId": "arn:aws:cloudformation:us-west-2:587010381366:stack/pelorus-vk-StreamStack-NAA3DJMELCFG/04990c30-7519-11e6-934e-50aXXXXX12f2",
            "LogicalResourceId": "StreamStack"
        
    ]

【问题讨论】:

【参考方案1】:

一种潜在的解决方法:将 --physical-resource-id 替换为 --stack-name 会导致我预期的行为,即使我提供了物理 ID

【讨论】:

以上是关于描述嵌套 CloudFormation 堆栈资源的正确方法是啥?的主要内容,如果未能解决你的问题,请参考以下文章

AWS cloudformation 嵌套堆栈因模板 URL 失败

yaml中的Cloudformation嵌套堆栈输出

对 CloudFormation 上的嵌套堆栈使用 CAPABILITY_AUTO_EXPAND

在 AWS cloudformation 上理解 Apigateway 和嵌套堆栈时出错

AWS CloudFormation CodePipeline、ParameterOverrides、将列表传递给嵌套堆栈

将现有 AWS 资源整合到 CloudFormation 堆栈中