【问题标题】:How can you pass variables between cdk stacks without getting cross reference error?如何在 cdk 堆栈之间传递变量而不会出现交叉引用错误?
【发布时间】:2021-05-29 20:32:00
【问题描述】:

我需要将 INamespace 传递给 CloudMapOptions 以便 ECS 任务注册到 AWS CloudMap,但出现以下错误。我无法将它们与 CfnOutput 解耦,因为我需要 ECS cloudMapOptions 中的命名空间:

   Stack "users" cannot consume a cross reference from stack "servicediscovery". Cross stack references are only supported for stacks deployed to the same environment or between nested stacks and their parent stack.

我试过这个:https://bobbyhadz.com/blog/aws-cdk-share-vpc-between-stacks,但没有任何成功。如何在堆栈之间传递 INamespace 类型的变量?

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation aws-cdk clouddevelopmentkit


    【解决方案1】:

    如果您执行以下操作之一,则可能会发生此错误:

    1. 您尝试在定义为位于 2 个不同区域的堆栈之间创建引用

    注意这样的跨域references are not supported

    1. 您将不同的StackProps 作为第三个参数提供给Stack 构造函数

    为了解决这个问题,请确保在StackProps 中传递相同的env 值,例如

    class MyStack extends Stack {
      constructor(scope: Construct){
        super(scope, "MyStack", {
          env: { 
            account: '123456789', 
            region: 'eu-central-1'
          }
        })
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-08-14
      • 1970-01-01
      • 2022-01-03
      • 1970-01-01
      • 2015-12-21
      • 1970-01-01
      相关资源
      最近更新 更多