如何在Java 8中使lambda函数报告失败?
我认为这在Node.js中是可能的。
http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html
使用回调参数 Node.js运行时v4.3支持可选的回调参数。您可以使用它显式地将信息返回给调用方。一般的语法是:
callback(Error error, Object result);
其中:
Note
使用回调参数是可选的。如果不使用可选的回调参数,则行为与调用没有任何参数的回调()相同。可以在代码中指定回调以将信息返回给调用方。
如果代码中不使用回调,AWS将隐式调用它,返回值为null。
当回调被调用(显式或隐式)时,AWS将继续Lambda函数调用,直到Node.js事件循环为空。
以下是示例回调:
callback(); // Indicates success but no information returned to
the caller. callback(null); // Indicates success but no information
returned to the caller. callback(null, "success"); // Indicates
success with information returned to the caller. callback(error);
// Indicates error with error information returned to the caller.
AWS Lambda将错误参数的任何非空值视为已处理的异常。
发布于 2016-08-02 15:28:21
只需抛出一个异常,不要在任何地方捕获它。任何未捕获的异常都会导致Lambda失败。您可以看到更多有关如何用Java:https://docs.aws.amazon.com/lambda/latest/dg/java-exceptions.html报告AWS故障的信息。
public TestResponse handleRequest(TestRequest request, Context context) throws RuntimeException {
throw new RuntimeException("Error");
}
注意throws
声明,它允许将未处理的异常抛出该方法。
https://stackoverflow.com/questions/38724359
复制相似问题