maxmoore14
maxmoore14

Reputation: 877

How to create EventBridge Rule with Lambda Target using the .NET SDK

  1. I have an existing Lambda function.
  2. I can use the console to create a new Rule with my Lambda as the Target.
  3. When I do so via the console, it automatically creates a "EventBridge (CloudWatch Events)" Trigger which is visible on the Lambda configuration screen.
  4. The Rule executes and successfully invokes the Lambda.

Attempting to automate the above steps using C# and the SDK (nuget package: AWSSDK.EventBridge), I take the following steps:

  1. I call PutRule successfully.
  2. I call PutTarget successfully

The Rule & Target look perfectly normal and functional in the EventBridge console, but the Trigger does not appear on the Lambda function at all and the Lambda is never invoked by the Rule.

If I now edit the Rule, don't change anything but just click Update in the console, it wires it up successfully with a Trigger.

I'm guessing it is one of two scenarios:

  1. I need to add an additional request to my code - something like PutTriggerOnLambda
  2. Or I am simply missing IAM permissions and it is failing silently

Anyone have a suggestion?

Upvotes: 1

Views: 2275

Answers (1)

maxmoore14
maxmoore14

Reputation: 877

I got some really good technical support from AWS and learned that the step I was missing was to Add Permission to the lambda function to allow the Event Bridge Rule to trigger it.

This doc explains the situation: https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CWE_Troubleshooting.html#LAMfunctionNotInvoked

This doc 2.2 explains the missing step via CLI: https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/RunLambdaSchedule.html

And this doc explains how to do it via SDK: https://docs.aws.amazon.com/lambda/latest/dg/API_AddPermission.html

Upvotes: 1

Related Questions