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

前端 未结 9 1288
面向向阳花
面向向阳花 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:33

    I achieved this by placing the following line of code:

    callback(null, "message");

    Into my function such as the below update to DynamoDB. When there is an error, rather than retrying for hours on end, this callback outside of the if / else will stop the retries.

    dynamodb.updateItem(params, function(err, data){
                     if (err) {
                        console.log(err)
                        callback(err, data)
                } else {
                     console.log(data);
                     callback(null, data);
               }
               callback(null, "message");
            });
    
    0 讨论(0)
  • 2020-12-05 07:36

    If you call the function asynchronously, in the Console, under Function configuration, you can modify the Retry attempts:

    0 讨论(0)
  • 2020-12-05 07:39

    As mentioned before, this feature has been added lately. To achieve this behaviour using cloudformation you will need both an AWS::Lambda::Version and AWS::Lambda::EventInvokeConfig:

      MyLambda:
        Type: AWS::Serverless::Function
        Properties:
          FunctionName: my-lambda-dev
          ...
    
      MyLambdaVersion:
        Type: AWS::Lambda::Version
        Properties:
          FunctionName: !Ref MyLambda
    
      MyLambdaAsyncConfig:
        Type: AWS::Lambda::EventInvokeConfig
        Properties:
          FunctionName: !Ref MyLambda
          MaximumRetryAttempts: 0
          Qualifier: !GetAtt MyLambdaVersion.Version
    
    0 讨论(0)
提交回复
热议问题