Skip to content

(aws-events): event bus doesn't respect physical names #14337

@liveFreeOrCode

Description

@liveFreeOrCode

When trying to create an eventbus in account 111111111 and make it a target for an eventbus in account 222222222. It results in the following error, even with a PhysicalName.GENERATE_IF_NEEDED specified. I have also tried just hardcoding the eventbus name as well:

Error: Resolution error: Resolution error: Resolution error: Resolution error: Cannot use resource 'StackA/EventBus' in a cross-environment fashion, the resource's physical name must be explicit set or use `PhysicalName.GENERATE_IF_NEEDED`.

Reproduction Steps

import { EventBus, Rule } from "@aws-cdk/aws-events";
import * as cdk from "@aws-cdk/core";
import { PhysicalName } from "@aws-cdk/core";
import * as targets from "@aws-cdk/aws-events-targets";

export class StackA extends cdk.Stack {
  public eventBus: EventBus;

  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);
    this.eventBus = new EventBus(this, "EventBus", {
      eventBusName: PhysicalName.GENERATE_IF_NEEDED,
    });
  }
}

interface StackBProps extends cdk.StackProps {
  stackABus: EventBus;
}
export class StackB extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props: StackBProps) {
    super(scope, id, props);

    const stackBBus = new EventBus(this, "EventBus", {
      eventBusName: PhysicalName.GENERATE_IF_NEEDED,
    });
    const stackABusTarget = new targets.EventBus(props.stackABus);
    new Rule(this, "Rule", {
      eventBus: stackBBus,
      eventPattern: { source: ["*"] },
      targets: [stackABusTarget],
    });
  }
}

const app = new cdk.App();

const stackA = new StackA(app, "StackA", { env: { account: "111111111" } });

new StackB(app, "StackB", {
  stackABus: stackA.eventBus,
  env: { account: "222222222" },
});

What did you expect to happen?

I expected to be able to make an event bus from one account the target for a rule on an event bus in a different account as per the documentation found here: https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CloudWatchEvents-CrossAccountEventDelivery.html

What actually happened?

An error occurred, telling me I needed to specify a PhysicalName.GENERATE_IF_NEEDED, although it was specified as such.

Environment

  • CDK CLI Version: 1.100.0
  • Framework Version: 1.100.0
  • Node.js Version: v14.15.4
  • OS : Windows WSL2 Ubuntu 18.04.5 LTS
  • Language (Version): TypeScript (3.9.7)

Other

➜  testCdk git:(main) ✗ CDK_DEBUG=true yarn cdk synth --all
yarn run v1.22.10
warning package.json: No license field
$ cdk synth --all
Error: Resolution error: Resolution error: Resolution error: Resolution error: Cannot use resource 'StackA/EventBus' in a cross-environment fashion, the resource's physical name must be explicit set or use `PhysicalName.GENERATE_IF_NEEDED`.
Object creation stack:
  at new Intrinsic (/home/matt/dev/testCdk/node_modules/@aws-cdk/core/lib/private/intrinsic.ts:42:55)
  at new Reference (/home/matt/dev/testCdk/node_modules/@aws-cdk/core/lib/reference.ts:22:5)
  at new <anonymous> (/home/matt/dev/testCdk/node_modules/@aws-cdk/core/lib/resource.ts:300:29)
  at mimicReference (/home/matt/dev/testCdk/node_modules/@aws-cdk/core/lib/resource.ts:300:25)
  at EventBus.getResourceArnAttribute (/home/matt/dev/testCdk/node_modules/@aws-cdk/core/lib/resource.ts:268:12)
  at new EventBus (/home/matt/dev/testCdk/node_modules/@aws-cdk/aws-events/lib/event-bus.ts:298:29)
  at new StackA (/home/matt/dev/testCdk/lib/test_cdk-stack.ts:11:21)
  at Object.<anonymous> (/home/matt/dev/testCdk/bin/test_cdk.ts:8:16)
  at Module._compile (internal/modules/cjs/loader.js:1063:30)
  at Module.m._compile (/home/matt/dev/testCdk/node_modules/ts-node/src/index.ts:1056:23)
  at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
  at Object.require.extensions.<computed> [as .ts] (/home/matt/dev/testCdk/node_modules/ts-node/src/index.ts:1059:12)
  at Module.load (internal/modules/cjs/loader.js:928:32)
  at Function.Module._load (internal/modules/cjs/loader.js:769:14)
  at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
  at main (/home/matt/dev/testCdk/node_modules/ts-node/src/bin.ts:198:14)
  at Object.<anonymous> (/home/matt/dev/testCdk/node_modules/ts-node/src/bin.ts:288:3)
  at Module._compile (internal/modules/cjs/loader.js:1063:30)
  at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
  at Module.load (internal/modules/cjs/loader.js:928:32)
  at Function.Module._load (internal/modules/cjs/loader.js:769:14)
  at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
  at internal/main/run_main_module.js:17:47.
Object creation stack:
  at Function.any (/home/matt/dev/testCdk/node_modules/@aws-cdk/core/lib/lazy.ts:306:12)
  at new Rule (/home/matt/dev/testCdk/node_modules/@aws-cdk/aws-events/lib/rule.ts:136:21)
  at new StackB (/home/matt/dev/testCdk/lib/test_cdk-stack.ts:28:5)
  at Object.<anonymous> (/home/matt/dev/testCdk/bin/test_cdk.ts:10:1)
  at Module._compile (internal/modules/cjs/loader.js:1063:30)
  at Module.m._compile (/home/matt/dev/testCdk/node_modules/ts-node/src/index.ts:1056:23)
  at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
  at Object.require.extensions.<computed> [as .ts] (/home/matt/dev/testCdk/node_modules/ts-node/src/index.ts:1059:12)
  at Module.load (internal/modules/cjs/loader.js:928:32)
  at Function.Module._load (internal/modules/cjs/loader.js:769:14)
  at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
  at main (/home/matt/dev/testCdk/node_modules/ts-node/src/bin.ts:198:14)
  at Object.<anonymous> (/home/matt/dev/testCdk/node_modules/ts-node/src/bin.ts:288:3)
  at Module._compile (internal/modules/cjs/loader.js:1063:30)
  at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
  at Module.load (internal/modules/cjs/loader.js:928:32)
  at Function.Module._load (internal/modules/cjs/loader.js:769:14)
  at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
  at internal/main/run_main_module.js:17:47..
    at EventBus._enableCrossEnvironment (/home/matt/dev/testCdk/node_modules/@aws-cdk/core/lib/resource.ts:190:13)
    at Object.produce (/home/matt/dev/testCdk/node_modules/@aws-cdk/core/lib/resource.ts:272:16)
    at Object.resolve (/home/matt/dev/testCdk/node_modules/@aws-cdk/core/lib/resource.ts:302:23)
    at RememberingTokenResolver.resolveToken (/home/matt/dev/testCdk/node_modules/@aws-cdk/core/lib/resolvable.ts:147:24)
    at RememberingTokenResolver.resolveToken (/home/matt/dev/testCdk/node_modules/@aws-cdk/core/lib/private/resolve.ts:273:18)
    at resolve (/home/matt/dev/testCdk/node_modules/@aws-cdk/core/lib/private/resolve.ts:202:51)
    at Object.resolve [as mapToken] (/home/matt/dev/testCdk/node_modules/@aws-cdk/core/lib/private/resolve.ts:112:77)
    at TokenizedStringFragments.mapTokens (/home/matt/dev/testCdk/node_modules/@aws-cdk/core/lib/string-fragments.ts:71:33)
    at RememberingTokenResolver.resolveString (/home/matt/dev/testCdk/node_modules/@aws-cdk/core/lib/resolvable.ts:168:22)
    at RememberingTokenResolver.resolveString (/home/matt/dev/testCdk/node_modules/@aws-cdk/core/lib/private/resolve.ts:277:23)
npm ERR! code 1
npm ERR! path /home/matt/dev/testCdk
npm ERR! command failed
npm ERR! command sh -c ts-node "--prefer-ts-exts" "bin/test_cdk.ts"

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/matt/.npm/_logs/2021-04-23T02_32_25_405Z-debug.log
Subprocess exited with error 1
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

This is 🐛 Bug Report

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-eventsRelated to CloudWatch EventsbugThis issue is a bug.effort/smallSmall work item – less than a day of effortgood first issueRelated to contributions. See CONTRIBUTING.mdp1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions