typescriptaws-cloudformationaws-cdkaws-cdk-typescript

CDK Stack Export Resource not Found


I'm trying to import values generated and exported from a cdk stack that deploys into eu-west-1 into a stack that needs to be deployed into af-south-1 but I keep getting the error that the export name does not exist:

EU

new CfnOutput(this, 'userPoolArn', {
value: this.userPoolPattern.userPoolArn,})

AF

const userPoolArn = cdk.Fn.importValue('EuWest1Infrastructure:userPoolArn');

Error: AfSouth1Infrastructure | 0/44 | 20:10:55 | ROLLBACK_IN_PROGRESS | AWS::CloudFormation::Stack | AfSouth1Infrastructure No export named EuWest1Infrastructure:userPoolArn found. Rollback requested by user.

I've tried using the value that gets outputted in the console but it returns the same error.


Solution

  • To create a cross-region cross-stack reference, set the crossRegionReferences Stack prop to true and simply pass the reference around. Here is an example from the docs:

    const stack1 = new Stack(app, 'Stack1', {
      env: {
        region: 'us-east-1',
      },
      crossRegionReferences: true,
    });
    const cert = new acm.Certificate(stack1, 'Cert', {
      domainName: '*.example.com',
      validation: acm.CertificateValidation.fromDns(route53.PublicHostedZone.fromHostedZoneId(stack1, 'Zone', 'Z0329774B51CGXTDQV3X')),
    });
    
    const stack2 = new Stack(app, 'Stack2', {
      env: {
        region: 'us-east-2',
      },
      crossRegionReferences: true,
    });
    new cloudfront.Distribution(stack2, 'Distribution', {
      defaultBehavior: {
        origin: new origins.HttpOrigin('example.com'),
      },
      domainNames: ['dev.example.com'],
      certificate: cert,
    });
    

    Here, the cert construct is simply passed around and the necessary cross-region references are created automatically. You can do the same with your UserPool.

    This feature is experimental as of CDK 2.114.1