AWS Lambda automatically monitors Lambda functions on your behalf, reporting metrics through Amazon CloudWatch. To help you troubleshoot failures in a function, after you set up permissions, Lambda logs all requests handled by your function and also automatically stores logs generated by your code through Amazon CloudWatch Logs.
You can insert logging statements into your code to help you validate that your code is working as expected. Lambda automatically integrates with CloudWatch Logs and pushes all logs from your code to a CloudWatch Logs group associated with a Lambda function, which is named /aws/lambda/.
You can view logs for Lambda functions using the Lambda console, the CloudWatch console, the AWS Command Line Interface (AWS CLI), or the CloudWatch API. This page describes how to view logs using the Lambda console.
Note
It may take 5 to 10 minutes for logs to show up after a function invocation.
Topics
Your execution role needs permission to upload logs to CloudWatch Logs. You can add CloudWatch Logs permissions using the AWSLambdaBasicExecutionRole
AWS managed policy provided by Lambda. To add this policy to your role, run the following command:
aws iam attach-role-policy --role-name your-role --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
For more information, see AWS managed policies for Lambda features.
There is no additional charge for using Lambda logs; however, standard CloudWatch Logs charges apply. For more information, see CloudWatch pricing.
To view logs using the Lambda console
-
Open the Functions page of the Lambda console.
-
Choose a function.
-
Choose Monitor.
-
Choose View logs in CloudWatch.
To debug and validate that your code is working as expected, you can output logs with the standard logging functionality for your programming language. The Lambda runtime uploads your function's log output to CloudWatch Logs. For language-specific instructions, see the following topics:
- AWS Lambda function logging in Node.js
- AWS Lambda function logging in Python
- AWS Lambda function logging in Ruby
- AWS Lambda function logging in Java
- AWS Lambda function logging in Go
- Lambda function logging in C#
- AWS Lambda function logging in PowerShell
- Learn more about log groups and accessing them through the CloudWatch console in Monitoring system, application, and custom log files in the Amazon CloudWatch User Guide.