Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Add logs to AWS Lambda function and review them in CloudWatch


    Since AWS Lambda functions are running in the cloud, we need to be able to dig in to see what's going on in there (especially when we have issues with the function).

    This is where logs come in, AWS Lambda allows us to send logs from functions to various services, including CloudWatch

    In this lesson we're going to learn how to add logs to a lambda function and how to review them in CloudWatch



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    Instructor: 0:00 We can add logs to our Lambda functions. In order to do that in JavaScript, we just have to console.log it. I'm going to paste in a console.log statement, "Hello, the time is," and I'm going to display the current time.

    0:11 If I save this Lambda function and press the Test button in order to send a test event, I would be able to see the execution result over here. Inside of the logs, we can see "Hello, the time is," and the current date.

    0:23 This Lambda function has an API gateway attached to it. If I click over here, in order to get the endpoint, and I click here, I'm going to execute my Lambda function. Where do I see those logs? In order to see the logs, go back to the AWS console, click on the Monitoring tab, and here we can see several CloudWatch metrics. We can see the duration of our function, the error count, and many others.

    0:46 Over here, we can click to view the logs in CloudWatch. CloudWatch is a logging service provided by AWS. Here we can see several log streams of our function. We're going to click on the newest one, because we just executed the function.

    0:59 Here we can see all the recent logs. If I scroll down in order to open one of those, I'm going to see the log that I added to console.log earlier, so "Hello, the time is," and the current time.

    1:10 Every time you execute a Lambda function, there will be some things logged out automatically. There's an automatic log whenever the function starts, whenever the function ends, and also a report at the end of the function invocation. This function took roughly a millisecond in order to execute.