使用嵌套堆栈部署 AWS sam - 来自子堆栈的错误不会冒泡

时间:2021-01-30 17:09:26

标签: amazon-web-services amazon-cloudformation

我刚刚开始我的无服务器/云形成/AWS SAM 之旅。我创建了一个具有 AWS::CloudFormation::Stack 类型资源的堆栈,并将我的一些资源分离到该子堆栈中。

当我执行 sam buildsam deploy 时,出现以下错误:

Embedded stack arn:aws:cloudformation:us-
west-2:111111111111:stack/ParentStack-
ChildStack-1QK94LXRA71CS/f9885e30-631c-11eb-
bfd8-021cb123b7ed was not successfully created: The
following resource(s) failed to create: [DynamoDBTable]. 
-
The following resource(s) failed to create:
[ChildStack].

当然,我真正想知道的是嵌套堆栈中的哪个资源未能创建,以及为什么。当我将子堆栈中的资源复制/粘贴到父 .yaml 文件并重建/重新部署时,我看到:

 One or more parameter values were invalid: Some index key
 attributes are not defined in AttributeDefinitions. Keys:
 [userID], AttributeDefinitions: [userId] (Service:
 AmazonDynamoDBv2; Status Code: 400; Error Code:
 ValidationException; Request ID:
 SMJDHUT0CQKM8IBQJVMAIJM4RRVV4KQNSO5AEMVJF66Q9ASUAAJG;    
 Proxy: null)

这就是我在构建父堆栈时希望在输出中看到的:导致子堆栈失败的错误。

这导致我使用了一个相当曲折的工作流程:在主堆栈中构建资源,然后在它们正确构建时将它们分离到一个独立的堆栈中。一定有更好的方法,我相信社区知道我不知道的东西。

在 CloudFormation 列车上,你们都是如何调试子堆栈的?

1 个答案:

答案 0 :(得分:0)

这是正常行为,您必须从 AWS Console 获得帮助或在这种情况下使用 AWSW CLI

Deploy error reporting is not showing the reason of failure when using nested stacks. #5974

Feature Requests for nested stacks

Why doesn't the error tell me what's wrong?

<块引用>

CloudFormation 将资源的创建和更新传递给负责这些资源的服务。当资源无法创建/更新时,资源的后备服务会向堆栈返回一个原因,该原因在事件中记录为状态原因。 Child StackCloudFormation::Stack 资源,因此它由 CloudFormation 创建。据 CloudFormation 所知,它在尝试实际执行任何操作时都没有遇到错误。它所做的与 CloudFormation 方面相关的一切都很好;归咎于未能创建它的服务资源。因此,Child Stack 告诉 Parent-Stack 它失败只是因为 Service 无法创建,而不是因为 CloudFormation Service 方面的问题。

您可以在此处阅读更多相关信息CloudFormation troubleshooting