简体   繁体   English

NestedStacks 和 Constructs 之间的权衡是什么?

[英]What are the tradeoffs between NestedStacks and Constructs?

I'm trying to understand the use case of Nested Stacks vs. Constructs specifically in CDK.我正在尝试专门在 CDK 中了解嵌套堆栈与构造的用例。 The AWS docs say the following: AWS 文档说以下内容:

Stacks are the unit of deployment: everything in a stack is deployed together.堆栈是部署单元:堆栈中的所有内容都部署在一起。 So when building your application's higher-level logical units from multiple AWS resources, represent each logical unit as a Construct, not as a Stack.因此,当从多个 AWS 资源构建应用程序的更高级别的逻辑单元时,将每个逻辑单元表示为一个 Construct,而不是一个 Stack。 Use stacks only to describe how your constructs should be composed and connected for your various deployment scenarios.仅使用堆栈来描述应如何为各种部署方案组合和连接构造。

This makes sense when evaluating whether to use a Construct or Stack, but what about Nested Stacks?在评估是使用构造还是堆栈时,这是有道理的,但是嵌套堆栈呢? Both Constructs and Nested Stacks solve the problems of:构造和嵌套堆栈都解决了以下问题:

  • reusability of component architectures组件架构的可重用性
  • controlled information sharing between components / mitigating import and export (deadly embrace) issues组件之间的受控信息共享/缓解导入和导出(致命拥抱)问题
  • and both Constructs and Nested Stacks are deployed together from the root Stack (from what I understand, NestedStacks are rarely deployed alone and are intended to be deployed as part of a group of NestedStacks under one parent Stack)并且 Constructs 和 Nested Stacks 都是从根 Stack 部署的(据我了解,NestedStacks 很少单独部署,并且打算作为一组 NestedStacks 的一部分部署在一个父 Stack 下)

So what's the benefit of using Nested Stacks over Constructs besides working around the resource limitations of a single Stack (ie when should I use one over the other)?那么除了解决单个堆栈的资源限制(即我什么时候应该使用一个堆栈)之外,使用嵌套堆栈而不是构造有什么好处?

It's instructive how differently the CloudFormation docs and CDK docs present Nested Stacks. CloudFormation 文档和 CDK 文档呈现嵌套堆栈的方式有多么不同,这很有启发意义。 The CloudFormation docs focus on their role in component resuse. CloudFormation 文档专注于它们在组件重用中的作用。 The CDK docs don't mention reuse, instead presenting them as a workaround for the per-stack resource limit. CDK 文档没有提到重用,而是将它们作为每个堆栈资源限制的解决方法。 Of course, Nested Stacks do both things.当然,嵌套堆栈可以做这两件事。

CDK Constructs are more composable and portable than the Nested Stacks it inherited from CloudFormation. CDK 构造比它从 CloudFormation 继承的嵌套堆栈更具可组合性和可移植性。 The CDK docs recommend Constructs for composition here and here . CDK 文档在此处此处推荐 Constructs for composition。

Apart from overcoming the per-stack resource limit, there is a backwards compatability rationale for using Nested Stacks when including existing CloudFormation templates into CDK apps.除了克服每个堆栈的资源限制之外,在将现有 CloudFormation 模板包含到 CDK 应用程序中时,使用嵌套堆栈还有一个向后兼容的理由。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM