I have attached SNS as destination on failure of Kinesis data stream trigger in my Lambda function. On any kind of failure, I receive an email of the format:
{"requestContext":{"requestId":"xxx","functionArn":"xxx","condition":"RetryAttemptsExhausted","approximateInvokeCount":2},"responseContext":{"statusCode":200,"executedVersion":"$LATEST","functionError":"Unhandled"},"version":"1.0","timestamp":"2021-06-30T15:19:20.847Z","KinesisBatchInfo":{"shardId":"shardId-xxx","startSequenceNumber":"xxx","endSequenceNumber":"xxxx","approximateArrivalOfFirstRecord":"xxx","approximateArrivalOfLastRecord":"xxx","batchSize":100,"streamArn":"xxx"}}
Here, I am receiving functionError
as Unhandled
. Whereas I want to know the exact reason of Lambda failure. This SNS message neither contains the error message nor the lambda execution ARN or the log stream which I can look into to know the error details. In my Lambda code, I am doing something like below:
def lambda_handler(event, context):
try:
for record in event['Records']:
#Kinesis data is base64 encoded so decoding here
payload = base64.b64decode(record["kinesis"]["data"])
except Exception as e:
print(e)
raise e
The stack trace/error does get printed in the CloudWatch Logs, but the SNS message does not contain any error information. Can someone guide me how to include the error details in this SNS message or is there some change needed to be done in the code to include the error information in the SNS message. Thanks for any help in this regard!
You need to do it yourself. Instead of using build in lambdas destinations, you have to send such messages yourself in your code. So in your except
block you have to provide sns message to your queue:
except Exception as e:
print(e)
# "manually" publish msg with the error to your SNS.
raise e