4

I need to pass INamespace to CloudMapOptions in order that the ECS tasks register to the AWS CloudMap, I get following error. I can't decouple them with CfnOutput, because I need the namespace in the 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.

I tried this : https://bobbyhadz.com/blog/aws-cdk-share-vpc-between-stacks, but without any success. How can I pass a variable of type INamespace between stacks?

2 Answers2

5

This "cross reference" error can also be caused by missing third argument to super().

export class MyStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props: cdk.StackProps) {
    super(scope, id); // Missing third argument
  }
}
Ryan
  • 4,594
  • 1
  • 32
  • 35
4

This error likely happens if you do one of the following:

  1. You try to create a reference between stacks which are defined to live in 2 different regions

Note that such cross region references are not supported

  1. You supply different StackProps as 3rd parameter to Stack constructor

In order to resolve that please make sure to pass the same env value in StackProps e.g.

class MyStack extends Stack {
  constructor(scope: Construct){
    super(scope, "MyStack", {
      env: { 
        account: '123456789', 
        region: 'eu-central-1'
      }
    })
  }
}
miensol
  • 39,733
  • 7
  • 116
  • 112