AWS Lambda - How to stop retries when there is a failure

前端 未结 9 1403
面向向阳花
面向向阳花 2020-12-05 06:49

I know that when a Lambda function fails (for example when there is a time out), it tries to run the function 3 more times again. Is there any way to avoid this behavior? I\

9条回答
  •  没有蜡笔的小新
    2020-12-05 07:29

    Use below code to identify and stop retry when there is a failure.

      exports.handler = (event, context, callback) => {
          context.callbackWaitsForEmptyEventLoop = false;
          let lastReqId;
          if (lastReqId == context.awsRequestId) {
            console.log("Lambda auto retry detected. Aborting");// you can write your own logic to decide what to do with the failure data
            return context.succeed();
          } else {
            console.log("new context");
            lastReqId = context.awsRequestId;
          }
        };
    

    you can read more about it here

提交回复
热议问题