-
Notifications
You must be signed in to change notification settings - Fork 4.4k
(aws-iot-actions): Unable to bind two TopicRule with the same action of a lambda function #17508
Copy link
Copy link
Closed
Labels
@aws-cdk/aws-iot-actionsbugThis issue is a bug.This issue is a bug.effort/smallSmall work item – less than a day of effortSmall work item – less than a day of effortp1
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
@aws-cdk/aws-iot-actionsbugThis issue is a bug.This issue is a bug.effort/smallSmall work item – less than a day of effortSmall work item – less than a day of effortp1