0

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);
}
wonderful world
  • 10,969
  • 20
  • 97
  • 194

2 Answers2

2

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.

Shubham Dhingra
  • 186
  • 3
  • 13
1

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.
samtoddler
  • 8,463
  • 2
  • 26
  • 21
  • I'm using EventBridge Event Bus. I also set up the destination in AWS Console. I also have the code which I posted in the original question. But the event is not going to the EventBus or the Lamda it is targeting. There is no C# example that shows what type need to be returned form the **FunctionHandler**. Is it **CloudWatchEvent** or **PutEventRequest**. None of them worked for me. – wonderful world Dec 23 '20 at 19:42
  • It works for me only when I send the event to the EventBridge event bus using **AWSEventBridgeClient.PutEents**. With the destination set up, just returning the event from the **FunctionHandler** should work. – wonderful world Dec 23 '20 at 19:45
  • this works fine, not sure if you configured it by adding necessary permissions. Lambda Destination works only for lambdas which are called asynchronously. – samtoddler Dec 26 '20 at 12:50
  • How do I call Lambda Destination from a lambda asynchronously? – wonderful world Dec 27 '20 at 14:23
  • Please take a look at the post I've attached you can choose from 4 options while configuring the destination. – samtoddler Dec 27 '20 at 15:02
  • I have already configured the destination as **Event Bridge Event Bus**. How to call the Lambda which is trigged from the events from that **Event Bus** is my question. – wonderful world Dec 27 '20 at 15:08
  • something like this aws lambda invoke-async --function-name myfunction--invoke-args args.json – samtoddler Dec 27 '20 at 15:17
  • I am pretty much sure there must be the API call for the relevant one in the SDK. This is the API call https://docs.aws.amazon.com/lambda/latest/dg/API_InvokeAsync.html – samtoddler Dec 27 '20 at 16:32