考虑一个用 Java 编写的简单 Lambda:
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
public class Hello implements RequestHandler<Integer, String>{
public String handleRequest(int myCount, Context context) {
return String.valueOf(myCount);
}
}
处理程序接口定义为RequestHandler<InputType, OutputType>
,但是当我的 Lambda 对事件做出反应并且只是产生一些副作用时,输出类型是不必要的,我必须编写如下内容:
public class Hello implements RequestHandler<SNSEvent, Void>{
public Void handleRequest(SNSEvent snsEvent, Context context) {
...
return null;
}
}
这很烦人。
处理程序是否有替代方案RequestHandler
?void
:
public class Hello implements EventHandler<SNSEvent>{
public void handleEvent(SNSEvent snsEvent, Context context) {
...
}
}