Search code examples
javaamazon-web-servicesaws-lambdaaws-event-bridge

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)

Solution

  • 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.