-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
EventRules cannot have targets with the same Construct ID. #2377
Closed
robwettach opened this issue
Apr 25, 2019
· 1 comment
· Fixed by #2744 or MechanicalRock/tech-radar#14 · May be fixed by MechanicalRock/cdk-constructs#5, MechanicalRock/cdk-constructs#6 or MechanicalRock/cdk-constructs#7
Closed
EventRules cannot have targets with the same Construct ID. #2377
robwettach opened this issue
Apr 25, 2019
· 1 comment
· Fixed by #2744 or MechanicalRock/tech-radar#14 · May be fixed by MechanicalRock/cdk-constructs#5, MechanicalRock/cdk-constructs#6 or MechanicalRock/cdk-constructs#7
Labels
bug
This issue is a bug.
Comments
Merged
4 tasks
The bug is still present in version 0.33: fixed in #2744 |
rix0rrr
pushed a commit
that referenced
this issue
Jun 17, 2019
) Extend the Target for Event Rule Lambda cannot have same construct ID Two supported Event Targets resources with the same Construct ID but in different scopes cannot both be used as targets to the same EventRule: ``` Error: Duplicate event rule target with ID: Resource at EventRule.addTarget (.../node_modules/@aws-cdk/aws-events/lib/rule.js:57:19) at new EventRule (.../node_modules/@aws-cdk/aws-events/lib/rule.js:26:18) ``` Assuming a Lambda Function as a RuleTarget, the issue is that Function's asEventRuleTarget uses `node.id` as the id field for the EventRuleTargetProps ([source](https://github.com/awslabs/aws-cdk/blob/48d536b191fb205869ef6724b718540be1037135/packages/%40aws-cdk/aws-events-targets/lib/lambda.ts#L32)). This isn't unique, as it's just the ID that was passed when creating the Function construct - instead, it should use `node.uniqueId` ([source](https://github.com/awslabs/aws-cdk/blob/master/packages/%40aws-cdk/cdk/lib/construct.ts#L31-L36)). This needs to be globally unique as when calling EventRule.addTarget this value is used as a unique identifier ([source](https://github.com/awslabs/aws-cdk/blob/master/packages/@aws-cdk/aws-events/lib/rule.ts#L124-L126)). I fix the bug as suggested by @robwettach in the package `@aws-cdk/aws-events` by using 64-maximum chars taken from the `uniqueId` - that is unique across the same app. This changes affects every binding in the supported event targets ([source](https://github.com/made2591/aws-cdk/blob/feature/aws-events-targets-sqs/packages/%40aws-cdk/aws-events-targets/lib/)). Close #2377
This was referenced Aug 22, 2019
This was referenced Dec 12, 2019
This was referenced Jan 20, 2020
This was referenced Sep 24, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
Two Lambda
Function
s with the same Construct ID but in different scopes cannot both be used as targets to the sameEventRule
:The issue is that
Function
'sasEventRuleTarget
usesnode.id
as theid
field for theEventRuleTargetProps
(source). This isn't unique, as it's just the ID that was passed when creating theFunction
construct - instead it should usenode.uniqueId
(source). This needs to be globally unique as when calling EventRule.addTarget this value is used as a unique identifier (source).To Reproduce
Expected behavior
I can name my constructs in any manner I want, they can still be accepted as distinct EventRule targets without collision between two distinct construct instances.
Version:
The text was updated successfully, but these errors were encountered: