use*_*634 4 java amazon-web-services aws-lambda
如何在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);哪里:
error - 是一个可选参数,可用于提供失败的Lambda函数执行的结果.当Lambda函数>成功时,您可以传递null作为第一个参数.
result - 是一个可选参数,可用于提供成功执行函数的结果.提供的结果必须与JSON.stringify兼容.如果提供了错误,则忽略此参数.
注意
使用回调参数是可选的.如果不使用可选的回调参数,则行为与调用不带任何参数的callback()相同.您可以在代码中指定回调以将信息返回给调用者.
如果您不在代码中使用回调,AWS Lambda将隐式调用它,返回值为null.
当调用回调(显式或隐式)时,AWS Lambda继续Lambda函数调用,直到Node.js事件循环为空.
以下是示例回调:
callback(); // Indicates success but no information returned tothe caller. callback(null); // Indicates success but no informationreturned to the caller. callback(null, "success"); // Indicatessuccess with information returned to the caller. callback(error);
// Indicates error with error information returned to the caller.AWS Lambda将error参数的任何非null值视为已处理的异常.
只是抛出异常而不是在任何地方捕获它.任何未捕获的异常都会导致Lambda失败.您可以在以下网址中查看有关如何使用AWS Lambda报告故障的更多信息:https://docs.aws.amazon.com/lambda/latest/dg/java-exceptions.html
public TestResponse handleRequest(TestRequest request, Context context) throws RuntimeException {
throw new RuntimeException("Error");
}
Run Code Online (Sandbox Code Playgroud)
请注意throws允许将未处理的异常抛出方法的声明.
| 归档时间: |
|
| 查看次数: |
1120 次 |
| 最近记录: |