简体   繁体   中英

AWS lambda java with Event invocation type

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 (eg, 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM