Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
liveFreeOrCode opened this issue Apr 23, 2021 · 2 comments · Fixed by #17008
Closed

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

liveFreeOrCode opened this issue Apr 23, 2021 · 2 comments · Fixed by #17008
Labels
@aws-cdk/aws-events Related to CloudWatch Events bug This issue is a bug. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p1

Comments

@liveFreeOrCode
Copy link

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

@liveFreeOrCode liveFreeOrCode added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 23, 2021
@github-actions github-actions bot added the @aws-cdk/aws-events Related to CloudWatch Events label Apr 23, 2021
@rix0rrr rix0rrr changed the title (aws-events): Unable to create cross-account EventBus target (aws-events): event bus doesn't respect physical names Apr 23, 2021
@rix0rrr rix0rrr added effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p1 labels Apr 23, 2021
@rix0rrr
Copy link
Contributor

rix0rrr commented Apr 23, 2021

event buses probably don't respect physical names

@rix0rrr rix0rrr removed their assignment Apr 23, 2021
@ryparker ryparker removed the needs-triage This issue or PR still needs to be triaged. label Jun 1, 2021
@mergify mergify bot closed this as completed in #17008 Oct 19, 2021
mergify bot pushed a commit that referenced this issue Oct 19, 2021
…us (#17008)

fixes an issue where the generate when needed marker was not being
passed through to the physicalName

fix #14337


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this issue Feb 21, 2022
…us (aws#17008)

fixes an issue where the generate when needed marker was not being
passed through to the physicalName

fix aws#14337


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-events Related to CloudWatch Events bug This issue is a bug. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants