8

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)
Bravin Ninja
  • 113
  • 1
  • 6

2 Answers2

2

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.

Bravin Ninja
  • 113
  • 1
  • 6
1

You need to change you request handler from using RequestHandler<SQSEvent, String> to using RequestHandler<Map<String,String>, String>. This will also lead to additional changes in your class / functions.

EventBridge events (schedules or your events) will show up in the input as an json encoded string.

Personally, I find it easier to leverage the RequestStreamHandler defined in https://docs.aws.amazon.com/lambda/latest/dg/java-handler.html#java-handler-interfaces. There's also some sample code linked that you may find helpful around deserialization.

blr
  • 908
  • 4
  • 8
  • Ah, I think one thing that wasn't clear to me at first (hence the other answers I gave, which I've deleted) is that you're saying the class should _implement_ `RequestHandler, String>`, which means the method parameter should be `Map`. It makes sense now, but the question showed the method signature, so the prescription of what to change it to in this answer wasn't clear to me at first. – Garret Wilson Jun 27 '23 at 01:26