Debug with CloudWatch logs

  1. Open Postman to call api.

    • Click + to add a new tab.
    • Select GET method.
    • Enter URL of the listing API that recorded from the previous step.
    • Click Send. CloudWatchLog
    • After completing, the data of the Books table is returned. CloudWatchLog
  2. Open AWS Lambda console.

    • In the search bar, search for Lambda and select the service. CloudWatchLog
    • Click Functions on the left menu.
    • Choose the books_list function. CloudWatchLog
  3. At books_list page.

    • Click the Monitor tab.
    • Click the View CloudWatch logs button. CloudWatchLog
  4. At /aws/lambda/books_list page.

    • You will see all the log streams created. Click the latest log stream. CloudWatchLog
    • Inside the stream, you will see all the logs saved each time the function books_list is executed showing successful operations. CloudWatchLog
  5. Next, we will fix the code to make the function run failed. Copy the following code.

    data_books = client.scan(
        TableName='Book',
        IndexName='name-index'
    )
    
    • Back to books_list page.
      • Click the Code tab.
      • Change the code as the copied one above. (changing TableName=‘Books’ to TableName=‘Book’)
      • Click the Deploy button. CloudWatchLog
  6. After books_list is deployed successfully. Recall the API as in step 1, the error returned is Internal server error. CloudWatchLog

  7. Back to /aws/lambda/books_list CloudWatch Logs page.

    • Click the Refresh icon.
    • Click the latest log at the Log streams. CloudWatchLog
  8. At the detailed log page. You could see the error. The error is an AccessDeniedException because the Lambda function does not have permission to scan the incorrect table Book or it doesn’t exist. CloudWatchLog