I’ve created a lambda function using AWS cdk library and I would like to subscribe it to a SNS topic.
This lambda function is an instance of NodejsFunction
construct, which is an implementation of IFunction
. I’ve also created a topic in cdk and I am calling the method addSubscription(new LambdaSubscription(myLambda))
. However, I’m encountering the error
this.fn.addPermission is not a function at LambdaSubscription.bind
LambdaSubscription
expects an object which implements the interface IFunction
. Therefore, I’m not understanding this error as NodejsFunction
has a method addPermission
.
Here a wider code snippet:
const lambdaProcessMessage = new NodejsFunction(this, 'LambdaProcessMessage', {
props}
})
const topic = new Topic(this, "TopicSNSGlueJobsError", {
topicName: 'topicGlueJobsErrorIngestion'
})
topic.addToResourcePolicy(new PolicyStatement({
resources: [topic.topicArn],
actions: ["sns:Publish"],
effect: Effect.ALLOW,
principals: [new ServicePrincipal("events.amazonaws.com")]
}))
topic.addSubscription(new LambdaSubscription(lambdaProcessMessage))