My API(Python) is deployed on Amazon Lambda. The problem is when I request my API I get the internal server error. I can tail the Lambda logs but I don't see the actual error or stack trace where the code crashed. When I tail the logs I just get the following output.
START RequestId: 62341bgd-6231-11e8-8c5b-25793532a32u Version: $LATEST
END RequestId: 62341b0d-6231-1128-8r5b-2b793032a3ed
REPORT RequestId: 6234te0b-6rte-aaa8-au5a-21t93132r3rt Duration: 0.46 ms
How can I see the actual stack trace of my python api for debugging?
Using the Lambda consoleOpen the Functions page of the Lambda console. Choose a function. Choose Monitor. Choose View logs in CloudWatch.
There are two ways through which you can output logs from your function code: Use the print method – print(event) Use any logging library that writes to stdout or stderr – logging, aws-lambda-logging.
Log data can take up to twelve hours to become available for export from CloudWatch Logs. For real-time analysis and processing, use subscription filters.
Lambda always tries to write the Python stack trace to CloudWatch. Make sure your function has the required permissions:
{
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:eu-west-1:123456789012:*"
},
{
"Effect": "Allow",
"Action": "logs:CreateLogGroup",
"Resource": "*"
}
If you are using Lambda_basic_execution role, simple print in python will show logs in cloudwatch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With