How to use the @aws-cdk/core.App.isApp function in @aws-cdk/core

To help you get started, we’ve selected a few @aws-cdk/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / aws-cdk / packages / @aws-cdk / aws-events / lib / rule.ts View on Github external
resource: 'event-bus',
              resourceName: 'default',
              region: targetRegion,
              account: targetAccount,
            }),
          });
        }

        // Grant the source account permissions to publish events to the event bus of the target account.
        // Do it in a separate stack instead of the target stack (which seems like the obvious place to put it),
        // because it needs to be deployed before the rule containing the above event-bus target in the source stack
        // (CloudWatch verifies whether you have permissions to the targets on rule creation),
        // but it's common for the target stack to depend on the source stack
        // (that's the case with CodePipeline, for example)
        const sourceApp = this.node.root;
        if (!sourceApp || !App.isApp(sourceApp)) {
          throw new Error('Event stack which uses cross-account targets must be part of a CDK app');
        }
        const targetApp = targetProps.targetResource.node.root;
        if (!targetApp || !App.isApp(targetApp)) {
          throw new Error('Target stack which uses cross-account event targets must be part of a CDK app');
        }
        if (sourceApp !== targetApp) {
          throw new Error('Event stack and target stack must belong to the same CDK app');
        }
        const stackId = `EventBusPolicy-${sourceAccount}-${targetRegion}-${targetAccount}`;
        let eventBusPolicyStack: Stack = sourceApp.node.tryFindChild(stackId) as Stack;
        if (!eventBusPolicyStack) {
          eventBusPolicyStack = new Stack(sourceApp, stackId, {
            env: {
              account: targetAccount,
              region: targetRegion,
github aws / aws-cdk / packages / @aws-cdk / aws-events / lib / rule.ts View on Github external
}),
          });
        }

        // Grant the source account permissions to publish events to the event bus of the target account.
        // Do it in a separate stack instead of the target stack (which seems like the obvious place to put it),
        // because it needs to be deployed before the rule containing the above event-bus target in the source stack
        // (CloudWatch verifies whether you have permissions to the targets on rule creation),
        // but it's common for the target stack to depend on the source stack
        // (that's the case with CodePipeline, for example)
        const sourceApp = this.node.root;
        if (!sourceApp || !App.isApp(sourceApp)) {
          throw new Error('Event stack which uses cross-account targets must be part of a CDK app');
        }
        const targetApp = targetProps.targetResource.node.root;
        if (!targetApp || !App.isApp(targetApp)) {
          throw new Error('Target stack which uses cross-account event targets must be part of a CDK app');
        }
        if (sourceApp !== targetApp) {
          throw new Error('Event stack and target stack must belong to the same CDK app');
        }
        const stackId = `EventBusPolicy-${sourceAccount}-${targetRegion}-${targetAccount}`;
        let eventBusPolicyStack: Stack = sourceApp.node.tryFindChild(stackId) as Stack;
        if (!eventBusPolicyStack) {
          eventBusPolicyStack = new Stack(sourceApp, stackId, {
            env: {
              account: targetAccount,
              region: targetRegion,
            },
            stackName: `${targetStack.stackName}-EventBusPolicy-support-${targetRegion}-${sourceAccount}`,
          });
          new CfnEventBusPolicy(eventBusPolicyStack, `GivePermToOtherAccount`, {
github aws / aws-cdk / packages / @aws-cdk / aws-codepipeline / lib / pipeline.ts View on Github external
private requireApp(): App {
    const app = this.node.root;
    if (!app || !App.isApp(app)) {
      throw new Error(`Pipeline stack which uses cross-environment actions must be part of a CDK app`);
    }
    return app;
  }
}