[英]AWS-CDK: Passing cross-stack references props between multi region (cross-region) stacks in AWS- CDK
I have to deploy one stack, let's call it the parent stack in one region Them a second stack(child) needs to be deployed, in another region.我必须部署一个堆栈,我们称它为一个区域的父堆栈 他们需要在另一个区域部署第二个堆栈(子堆栈)。 The region of the second stack(child stack) can not include the region where the parent was deployed.第二个堆栈(子堆栈)的区域不能包括部署父级的区域。 The second stack can be deployed in multiple regions.第二个堆栈可以部署在多个区域中。
However, the second stack needs props from the first stack.但是,第二个堆栈需要来自第一个堆栈的道具。 Specifically, it needs an ARN value.具体来说,它需要一个 ARN 值。 The default region is us-east-1
.默认区域是us-east-1
。 That is where the parent stack will get deployed.这就是父堆栈将被部署的地方。
To solve this I attempted the following为了解决这个问题,我尝试了以下
1- First Attempt : 1-第一次尝试:
cfnOutput
in the parent and in the child I capture the value with cdk.Fn.ImportValue()
在父级和子级中创建了一个cfnOutput
我使用cdk.Fn.ImportValue()
捕获值2- Second Attempt : 2-第二次尝试:
from the lib/mystack file来自 lib/mystack 文件
export interface myStackProps extends cdk.StackProps {
principalKeyArn: string
}
from the bin/myapp file来自 bin/myapp 文件
const app = new cdk.App();
const regions = ["us-east-2"]
const primaryMRKey = new KmsMultiregionPrincipalKey(app, 'KmsMultiregionKeyStack')
for (let region of regions){
const envToDeploy = {region: region, account: "123456789123"}
new KmsReplicaKey(app, 'KmsReplicaKey-' + region, {env: envToDeploy, principalKeyArn: primaryMRKey.principalKeyArn } )
}
RESULT : Cross stack references are only supported for stacks deployed to the same environment or between nested stacks and their parent stack结果:仅部署到同一环境或嵌套堆栈与其父堆栈之间的堆栈支持跨堆栈引用
Question :问题:
Thanks in advance提前致谢
Use a Parameter Store value with a CustomResource .将 Parameter Store 值与CustomResource一起使用。
This answer has a full Typescript CDK example of cross-region refs. 这个答案有一个完整的 Typescript CDK 跨区域参考示例。
(I originally posted this as a comment because I thought the question was perhaps a duplicate. But on reflection, I see that the linked question and tags only mention CloudFormation, not the CDK. Seems the community gets the most benefit from keeping this question alive). (我最初将此作为评论发布,因为我认为这个问题可能是重复的。但经过反思,我发现链接的问题和标签只提到 CloudFormation,而不是 CDK。似乎社区从保持这个问题的活力中获得了最大的好处)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.