Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon lambda does not show python logs

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?

like image 624
Hassan Abbas Avatar asked Jun 13 '18 09:06

Hassan Abbas


People also ask

How do I enable logs in AWS Lambda?

Using the Lambda consoleOpen the Functions page of the Lambda console. Choose a function. Choose Monitor. Choose View logs in CloudWatch.

How do you log events in Lambda?

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.

How long does it take for CloudWatch logs to appear?

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.


2 Answers

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": "*"
    }
like image 50
FelixEnescu Avatar answered Oct 02 '22 04:10

FelixEnescu


If you are using Lambda_basic_execution role, simple print in python will show logs in cloudwatch.

like image 36
singh30 Avatar answered Oct 02 '22 05:10

singh30