aws-cloudformation - 如何在 CDK 应用程序内不同帐户中部署的 CDK 堆栈之间传递值?

标签 aws-cloudformation aws-cdk

从文档中可以看出,在应用程序内的 CDK 堆栈之间传递值的建议是简单地传递值。

If the two stacks are in the same AWS CDK app, just pass a reference between the two stacks. For example, save a reference to the resource's construct as an attribute of the defining stack (this.stack.uploadBucket = myBucket), then pass that attribute to the constructor of the stack that needs the resource.

但似乎只有当 CDK 堆栈位于一个帐户内时这才有效。

检查生成的模板后,它会生成堆栈输出和输入,并将其用于传递值。并且堆栈输入和输出无法在创建它们的帐户之外工作。

从部署在不同帐户中的堆栈传递值的推荐方法是什么?

最佳答案

我认为您不能将其视为单个 CDK 应用程序。这样的单个应用程序旨在部署在单个帐户中。您想要做的是使用此应用程序构造在两个不同的环境中部署两个不同的堆栈并在它们之间共享数据。但是,在共享堆栈中已部署的服务的数据时,您必须遵守 CloudFormation 本身所具有的相同限制。因此您必须解决这个问题。

所以我认为没有任何推荐的方法可以做到这一点,但也许您可以创建一些跨帐户角色,允许从 SSM 参数存储中写入/读取,并将其与自定义资源 lambda 结合起来以读取/写入来自/位于其他帐户的 SSM 存储中的数据。鉴于此,编写一些 CICD 工具可能会更容易,该工具无需任何 AWS 服务即可完成此操作,并且只需在部署期间将值从一个堆栈的输出传递到另一个堆栈的输入。

关于aws-cloudformation - 如何在 CDK 应用程序内不同帐户中部署的 CDK 堆栈之间传递值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71458218/

相关文章:

amazon-web-services - 无法处理 AWS 标记

aws-cdk - 使用 aws-cdk 进行本地开发

amazon-web-services - 难以在 AWS 云开发工具包 (CDK) 中传播标签

python - AWS CDK : Error when deploying Redis ElastiCache: Subnet group belongs to a different VPC than CacheCluster

aws-cloudformation - 模板(即基础设施即代码)相对于 API 调用的优势

amazon-web-services - AWS Cloudformation 与 github 集成

amazon-web-services - 如何在Cloudformation模板中将EIP分配给VPC的Autoscaling组

amazon-web-services - AWS 云形成 : Cognito LambdaTrigger CustomEmailSender - Property "Not currently supported by AWS CloudFormation." and CDK usage

amazon-elastic-beanstalk - AWS CDK : Get LoadBalancer ARN of ElasticBeanstalk Environment for ApiGateway VPC Link

amazon-web-services - AWS Cloudformation : Use existing SG Cidr Range, 但端口号不同