awsdocs / aws-cdk-guide

User guide for the AWS Cloud Development Kit (CDK).
Other
335 stars 222 forks source link

cross stack reference between nested stacks #337

Open octaneC8H18 opened 3 years ago

octaneC8H18 commented 3 years ago

I have two nested stacks in my cdk app. I want to pass the arn of the user pool defined in nested stack one to stack two. I have been struggling to find a way to do this days. AWS doc is no help. How do I do this? How to refer between nested stacks.

```

export default class mainAppStack extends Stack {

  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    new NestedStackOne(this, "nested-one");
    new nestedStackTwo(this, 'nested-two);
  }
}

export class nestedStackOne extends cdk.NestedStack {
  constructor( scope: cdk.Construct, id: string, props?: cdk.NestedStackProps ) {
    super(scope, id, props);

    new new cognito.UserPool(this, `Userpool`, {
     // ...configs
    });
  });

 }

export class nestedStackTwo extends cdk.NestedStack {
  constructor( scope: cdk.Construct, id: string, props?: cdk.NestedStackProps 
  ) {
    super(scope, id, props);

  });

 }