Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aws lambda not logging print statements

I have a lambda_handler function like:

def lambda_handler(event, context):
   print('test')

I can see the log output is passing to CloudWatch just fine. I can see the Start, End, Syntax errors, etc. so I don't think it's a permissions thing, but I cannot see my print statements anywhere. I have the following allowed in my IAM role:

Allow: logs:CreateLogGroup

Allow: logs:CreateLogStream

Allow: logs:PutLogEvents

like image 224
Alex Jenkins Avatar asked Feb 19 '20 04:02

Alex Jenkins


People also ask

How can I access the output of print statements from Lambda?

View Logs In The Console. The simplest way to see logs from your AWS lambda function is in the console. Navigate to the monitoring tab of your lambda function and click the “view logs in CloudWatch” button. You should now be inside CloudWatch viewing your log output.

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.

Why Lambda is not logging to CloudWatch?

To troubleshoot a Log group does not exist error from CloudWatch, confirm the following: Your Lambda function's execution role has sufficient permissions to write logs to CloudWatch. The log group resource in the IAM policy includes the name of your function.

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.

Does console log work in Lambda function?

You can use the Lambda console to view log output after you invoke a Lambda function. For more information, see Accessing Amazon CloudWatch logs for AWS Lambda.

What does Lambda logging include?

Your Lambda function comes with a CloudWatch Logs log group and a log stream for each instance of your function. The Lambda runtime environment sends details about each invocation to the log stream, and relays logs and other output from your function's code.


2 Answers

I was facing the same problem. For me the missing step was to hit the "deploy" button.

As silly as it sounds, it might save some time to a future reader.

like image 126
NublicPablo Avatar answered Oct 08 '22 04:10

NublicPablo


Hey i just faced exactly the same problem. I added several print statements to some very long dicts and afterwards i was not able to display additional print statements (The old print statements were still displayed). I deleted some of the print statements with higher data volume and now it just works fine. SO i guess it is a kind of storage problem.

like image 32
Ew Na Avatar answered Oct 08 '22 04:10

Ew Na