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-iot-actions): Unable to bind two TopicRule with the same action of a lambda function #17508

Closed
aritzg opened this issue Nov 15, 2021 · 4 comments · Fixed by #17521
Closed
Labels
@aws-cdk/aws-iot-actions bug This issue is a bug. effort/small Small work item – less than a day of effort p1

Comments

@aritzg
Copy link

aritzg commented Nov 15, 2021

What is the problem?

cdk synth throws when binding TopicRule to same LambdaFunctionAction

throw new Error(`There is already a Construct with name '${childName}' in ${typeName}${name.length > 0 ? ' [' + name + ']' : ''}`);
            ^
Error: There is already a Construct with name '**invokedByAwsIotRule**' in Function [fn-lambda]
    at Node.addChild ./node_modules/constructs/src/construct.ts:381:13)
    at new Node (./node_modules/constructs/src/construct.ts:58:22)
    at new ConstructNode (./node_modules/@aws-cdk/core/lib/construct-compat.ts:184:24)

Same error happens if more than one TopicRule is bind to function in any way.
For example in:

  • "actions" attr of new iot.TopicRule
  • rule.addAction(callLambdaFunc);
  • callLambdaFunc.bind(rule);

Reproduction Steps

const fnLambdaFunc = new lambda.Function(this, 'fn-lambda', {
      code: lambda.Code.fromAsset('resources/fn-lambda/target/lambda-0.0.1-SNAPSHOT.jar'),
      handler: 'com.fn.lambda.Lambda',
      runtime: lambda.Runtime.JAVA_11,
      timeout: cdk.Duration.seconds(30),
    });


const callLambdaFunc  = new actions.LambdaFunctionAction(fnLambdaFunc);
const a  = new iot.TopicRule(this, 'AppRule', {
      topicRuleName: 'AppRule', 
      sql: iot.IotSql.fromStringAsVer20160323("SELECT * as payload, topic() as topic FROM '+/+/app' "),
      actions: [callLambdaFunc],
    });

const b  =new iot.TopicRule(this,  'TestConnectionRule', {
      topicRuleName: 'TestConnectionRule', 
      sql: iot.IotSql.fromStringAsVer20160323("SELECT * as payload, topic() as topic FROM '$aws/events/presence/connected/+' "),
      actions: [callLambdaFunc],
    });

What did you expect to happen?

I expected two TopicRules would be bind to the same lambda function action.

What actually happened?

Error is thrown when trying "cdk synth"

CDK CLI Version

1.132.0

Framework Version

No response

Node.js Version

v16.13.0

OS

Ubuntu 20.04.2 LTS

Language

Typescript

Language Version

No response

Other information

No response

@aritzg aritzg added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 15, 2021
@skinny85
Copy link
Contributor

Thanks for opening the issue @aritzg!

@yamatatsu do you mind taking a look?

@aritzg
Copy link
Author

aritzg commented Nov 15, 2021

The whole error stack is as follows

Error: There is already a Construct with name 'invokedByAwsIotRule' in Function [gh-lambda]
    at Node.addChild (./node_modules/constructs/src/construct.ts:381:13)
    at new Node (./node_modules/constructs/src/construct.ts:58:22)
    at new ConstructNode (./node_modules/@aws-cdk/core/lib/construct-compat.ts:184:24)
    at Object.createNode (./node_modules/@aws-cdk/core/lib/construct-compat.ts:55:11)
    at new Construct (./node_modules/constructs/src/construct.ts:409:26)
    at new Construct (./node_modules/@aws-cdk/core/lib/construct-compat.ts:52:5)
    at new CfnElement (./node_modules/@aws-cdk/core/lib/cfn-element.ts:31:5)
    at new CfnRefElement (./node_modules/@aws-cdk/core/lib/cfn-element.ts:106:1)
    at new CfnResource (./node_modules/@aws-cdk/core/lib/cfn-resource.ts:68:5)
    at new CfnPermission (./node_modules/@aws-cdk/aws-lambda/lib/lambda.generated.ts:2772:9)

@skinny85 skinny85 added effort/small Small work item – less than a day of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Nov 15, 2021
@skinny85 skinny85 removed their assignment Nov 15, 2021
@yamatatsu
Copy link
Contributor

@aritzg Thanks for your polite report!
I was able to reproduct this error in a test and I'm fixing it!

@mergify mergify bot closed this as completed in #17521 Nov 18, 2021
mergify bot pushed a commit that referenced this issue Nov 18, 2021
…ions (#17521)

fix: #17508

----

*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
…ions (aws#17521)

fix: aws#17508

----

*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-iot-actions bug This issue is a bug. effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants