How to send a CloudWatchEvent from a lambda to an EventBridge destination

1.8k views Asked by At

I have a lambda which is triggered by an EventBridge custom bus. I want to send another event to the customer bus at the end of the function processing. I created a destination in the lambda to send to the same custom bus.

I have the following code where the function handler will return a CloudWatchEvent. This is not working.

public async Task<CloudWatchEvent<object>> FunctionHandler(CloudWatchEvent<object> evnt, ILambdaContext context)
{
    return await ProcessMessageAsync(evnt, context);
}
2

There are 2 answers

8
samtoddler On

Have you given a shot to AWS Lambda Destinations. There are 4 types of Destinations supported

  1. SQS Queue
  2. SNS Topic
  3. Event Bridge Event Bus
  4. Lambda Function itself.
0
Shubham Dhingra On

My lambda was being triggered by S3 input event (which is asynchronous), I tried adding destination on Lambda "success" to EventBridge bus, created a rule to capture that and send it to CloudWatch logs but it didn't seem to work.

Turns out, while creating the Rule in EventBridge, event pattern was set to:

{
  "source": ["aws.lambda"]
}

Which is what you get if you are using the console and selecting AWS Lambda as the AWS Service. Event Source

Infuriated, I couldn't seem to get it to work even with a simple event. On further inspection, I looked at the input event and realized that it wants lambda and not aws.lambda. It is also mentioned in the documentation: https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html

So to fix it, I changed it to

{
  "source": ["lambda"]
}

and it worked for me.