Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS EventBridge Target Java Lambda function

I am using a Java lambda function to put a custom event to the AWS EventBridge. The target of this eventbridge is another Java lambda function. How to receive the Event in the target lambda function? I mean what is the input type in the handleRequest method I have to use? Tried using ScheduledEvent as an input type but it didn't work. Searched many EventBridge API documents but didn't get the details as how to receive the data in the Java lambda function from Eventbridge.

The below is an example for receiving the SQS Event. In the same way what type I should use for the events triggered from EventBridge?

@Override
  public String handleRequest(SQSEvent event, Context context)
like image 374
Bravin Ninja Avatar asked Apr 09 '26 13:04

Bravin Ninja


2 Answers

Events from EventBridge are in the format of Cloudwatch ScheduledEvents. AWS Lambda Runtime can unmarshall the incoming json into com.amazonaws.services.lambda.runtime.events.ScheduledEvent:

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.ScheduledEvent;

public class Handler implements RequestHandler<ScheduledEvent, Boolean> {

    @Override
    public Boolean handleRequest(ScheduledEvent input, Context context) {
        return true;
    }
}
like image 94
timomeinen Avatar answered Apr 11 '26 02:04

timomeinen


I am able to access the Event as Map<String,Object>. The "detail" key in the map gives the actual values those are put in the Eventbridge.

like image 28
Bravin Ninja Avatar answered Apr 11 '26 03:04

Bravin Ninja



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!