跳至內容

What is the easiest way to view logs for a Lambda function in AWS CloudWatch?

0

What is the easiest way to view logs for a Lambda function in AWS CloudWatch? I'm using Lambda and want to see my function's logs after it runs. Where exactly in CloudWatch do I find them, and how can I filter the logs by a specific invocation?

1 個回答
1
已接受的答案

There are three main ways to view your Lambda function logs in CloudWatch:

  1. Using the Lambda console:
  • Go to the Lambda console
  • Select your function
  • Choose the "Monitor" tab
  • View the execution results in the "Logs" section
  • You can also check the "Details" section when using the console test feature
  1. Using the CloudWatch console:
  • Open the CloudWatch console
  • Navigate to the "Log groups" page
  • Find and select the log group for your Lambda function (it will be named "/aws/lambda/your-function-name")
  • Click on a log stream to see the detailed logs
  1. Using the AWS Command Line Interface (CLI):
  • You can retrieve logs using the AWS CLI with the --log-type command option
  • The logs can be decoded using base64

Each log stream corresponds to an instance of your function. To filter logs for a specific invocation, you can use AWS X-Ray to record details about the request and the log stream in the trace. The Lambda runtime automatically logs the start and end of each function invocation, including details like request ID, duration, memory usage, and more. Any console.log statements (or equivalent in your programming language) will appear in these logs.
Sources
CloudWatch for Newbies | AWS re:Post
Log and monitor Node.js Lambda functions - AWS Lambda
Viewing CloudWatch logs for Lambda functions - AWS Lambda
Log and monitor TypeScript Lambda functions - AWS Lambda

已回答 1 年前

AWS
支援工程師

已審閱 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。