[aws-events] Rule.addTarget(new LambdaFunction(Function.fromFunctionArn(...))) does not add trigger to Lambda
See original GitHub issueNo trigger on AWS Lambda for Rule Target in different CF Stack
-
Rule.addTarget(new LambdaFunction(Function.fromFunctionArn(...)))
does not add trigger to Lambda, where the Lambda is on another existing CF stack. The Rule has correct Lambda name in place and when I do edit+save on the Rule on AWS Console without changing anything, the trigger gets added to Lambda. -
We would like this Rule to be updated on every release to point a new Lambda (arn), so that in any time the Rule has only single target, but also the previous Lambda doesn’t have the trigger in place anymore.
Reproduction Steps
import { Function as LFunction } from "@aws-cdk/aws-lambda";
public eventSubscription = new Rule(
this,
"MyEvent for my Lambda",
{
eventBus: EventBus.fromEventBusArn(
this,
"My EventBus",
this.stack.getEnvrionmentVariable("eventBusArn")
),
eventPattern: {
detailType: [
"myEvent",
],
},
}
).addTarget(
new LambdaFunction(
LFunction.fromFunctionArn(
this,
"myLambda",
this.config.myLambdaArn
)
)
);
What did you expect to happen?
Expected the Lambda to have the trigger in place and thus get the events from EventBridge as input events.
What actually happened?
Lambda didn’t get any input trigger and didn’t get any events either.
Environment
- CLI Version : CDK 1.61.1 (?)
- Framework Version: CDK 1.61.1
- Node.js Version: NodeJS 12 (?)
- OS : aws/codebuild/standard:3.0… TBD
- Language (Version): Typescript (?)
Other
The Rule has correct Lambda name in place and when I do edit+save on the Rule on AWS Console without changing anything, the trigger gets added to Lambda.
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:14 (3 by maintainers)
I added permission for the Lambda for events.amazonaws.com principal in the same stack where the Lambda is created. Then the Rule specified in another started working. However, Lambda AWS Console does not show any triggers as source, but the resource policy (permissions tab) still shows the permission. So, it works, but AWS Console is a bit inconsistent.
In general, I tend to like the fact that a stack can’t modify resources in another stack. Not sure if this is by design or whether CF would need to have some additional permissions to be able to do cross stack changes while deploying the stack.
one workaround is like below use CfnPermission() instead of addpermission() :