0
votes

I want to write an AWS Lambda that uses the event invocation type. According to java-programming-model-handler-types I should do the following:

If you plan to invoke the Lambda function asynchronously (using the Event invocation type), the outputType should be void. For example, if you use AWS Lambda with event sources such as Amazon S3, Kinesis, and Amazon SNS, these event sources invoke the Lambda function using the Event invocation type.

I am looking for an example on how to write such a handler (Java) method.

There are plenty of examples for a Java handler that works with RequestResponse invocation type (e.g., public String myHandler(int myCount, Context context)). There are also examples for using streams (which, IIUC, are also just for RequestResponse invocation type). I could not find any example for a Java Lambda whose handler is handling an Event invocation type

1

1 Answers

2
votes

It will look like this:

public class MyFunction implements RequestHandler<eventType, Void> {

    public Void handleRequest(eventType event, Context context) {

        ...
        return null;
    }

}

The trick is knowing what class your event type will be. You can set eventType to Object, cause your function to be triggered once, and have it print the class name in the function to find out what the event type is going to be.