How do you look at console.log output of the amazon lambda function

时光总嘲笑我的痴心妄想 提交于 2019-12-22 03:21:25

问题


When you do a

console.log('Loading function');

in an amazon lambda function, where does that go?

My setup api gateway lambda function nodejs6.10 curl https://n2tredacted.execute-api.us-east-1.amazonaws.com/prod/redactedFunc


回答1:


AWS Lambda logs are written to CloudWatch Logs. Here's how to access them:

  1. select your Lambda function in the AWS console
  2. click the Monitoring tab
  3. choose View logs in CloudWatch

If you prefer to retrieve CloudWatch Logs outside of the AWS Console, then there are numerous CLI options:

  • awscli: aws logs get-log-events
  • github: jorgebastida/awslogs
  • github: TylerBrock/saw
  • serverless: sls logs (if using serverless)
  • samcli: sam logs (if using SAM)



回答2:


There are 2 ways to access logs of your Lambda Function.

Method 1 (Using Serverless CLI):

Navigate to the root of your project folder and enter this in your command line:

sls logs -f myFunctionName -t

-f is for specifying the function name and -t is live tailing the logs in the command line.

Method 2 (Using CloudWatch Logs):

Go to CloudWatch in the region where your function was deployed and head to Logs. You will find the logs of your function there.




回答3:


In the console Cloudwatch > Logs Or with awscli:

aws logs get-log-events  --log-group-name /aws/lambda/my_group_name_here --log-stream-name stream_name_here

Some special characters like $ need to be escaped with a preceding \




回答4:


If you are testing this with API Gateway, console.log won't print in Test of API test. But don't be confused it works fine and print logs in cloud watch.

Just go to monitoring tab of your lambda you will find your logs.



来源:https://stackoverflow.com/questions/47846959/how-do-you-look-at-console-log-output-of-the-amazon-lambda-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!