Are you creating a lambda function? Are you currently debugging wondering where you can access the output of your
Understanding how logs work is a common confusion area when working with AWS Lambda. Today, we’re going to clear up the confusion and get your hands on your AWS Lambda logs so that you can start to debug your Lambda function.
By the end of this article you’ll understand how and where console.log output goes from an AWS Lambda function, and also how to debug your AWS Lambda setup if you’re still not seeing log output.
Accessing AWS Lambda Console.Log Output
There are three main ways to access logs in AWS Lambda…
If you’re still not seeing your logs come through, then there are a few debugging steps you should take.
Method 1. 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. Alternatively you can go directly to CloudWatch rather than via the lambda UI. Navigate to CloudWatch and select “log groups” from the left navigation.
The pattern of your log group name should now be…
Method 2. View Logs With Serverless Framework
Sometimes you don’t want to leave your development environment to view log output. If you are using Serverless framework, you can view the log output of your function by running the command…
Read the Serverless Framework docs for more information.
Method 3. View Logs With AWS CLI
Or if you’re not using Serverless Framework (and just regular AWS) you can view the logs by using the AWS CLI.
Read the AWS docs for more information.
Still Not Seeing Logs In CloudWatch?
You might find that your lambda is still not showing log output. Here’s a couple of things you might want to double check whilst debugging…
Ensure You Have Invoked Your Lambda
It may seem obvious (or not) but do ensure that your Lambda has also been invoked—especially if you’ve made some changes to your Lambda setup.
The simplest way to do trigger your AWS Lambda is by executing a test event from within the AWS console. Click the “select a test event” dropdown” and press the “test” button to invoke your Lambda.
Ensure You’re Viewing The Region Of The Lambda
CloudWatch log groups are separated by region, so if you’re in the wrong region you won’t see your log output. Ensure that you’re looking at the same region a your Lambda function when in the AWS console. Or make sure that you’re passing the correct region as part of your CLI setup.
Ensure Your Lambda Has The Correct Permissions
In order for Lambda to log to CloudWatch it needs a log group to be created and two sets of permissions allocated to the function:
putLogEvents. These permissions give the lambda the required permissions in order to log.
If your Lambda permissions are not correctly configured there’s no easy way to alert you to the fact that logs are not being shipped to CloudWatch. So be sure to check that your assigned AWS Lambda role has these at least these permissions.
Ensure The Log Group Is Correctly Named
Lastly if you’re still having issues, consider that the Lambda can only push to a log group of the same name as the lambda function. If you created your CloudWatch log group manually, ensure that the CloudWatch group name adhere’s to the following format…
Have Fun With Lambda Logs
Hopefully you’re now well on your way to an AWS Lambda setup emitting logs correctly! I do admit, accessing Lambda logs can be a bit fiddly at first, but you’ll soon get used to navigating to CloudWatch to see the log output.
That said, if you find yourself getting tired of clicking around in the AWS console, setup the CLI and use the commands to access your logs.
Speak soon Cloud Native friends!
- Open Up The Cloud Newsletter #23 (April Recap 2021) - May 6, 2021
- Cloud Software Engineering Newsletter #22 (March Recap 2021) - April 7, 2021
- Is An AWS Certification Enough To Get You A Job? (Spoiler Alert: No) - March 30, 2021