How to discard records?

时间:2017-10-12 10:16:23

标签: aws-lambda amazon-kinesis

I send events to AWS Kinesis and these are processed by an AWS lambda function. However, if the lambda throws some error, the records are not discarded, and are processed over and over again, blocking the processing of new records.

I would like rather to skip the faulty record and digest new records. I don't understand how to do that.

The lambda function catches any exception, so it should not give any execution error.

Here below the snippet in python.

I understand that lambda should be retried during the "retention" period (24h default), but I would like to discard and eventually log any kind of errors

def ProcessKinesisRecords(event, context):
    body = "ok"   
    response_code = 200
    for record in event['Records']:
        # Kinesis data is base64 encoded so decode here
        try:
            payload = base64.b64decode(record["kinesis"]["data"])
            #...payload processing
        except Exception as e:
            body = e 

    return {"isBase64Encoded": True, "statusCode": response_code, "headers": { "x-custom-header": "headerValue" }, "body": body}

I think I followed this lambda retries...but I don't see what I am doing wrong

1 个答案:

答案 0 :(得分:0)

嗯,实际上我没有抓住所有异常。 在python中

except Exception as e:

没有捕获所有例外:Difference between except: and except Exception as e: in Python

它不会捕获BaseException或系统退出异常SystemExit,KeyboardInterrupt和GeneratorExit。 这就是它无法正常工作的原因。