tailing aws lambda/cloudwatch logs

蹲街弑〆低调 提交于 2019-12-12 08:35:16

问题


Found out how to access lambda logs from another answer

Is it possible to tail them? (manually pressing refresh is cumbersome)


回答1:


Since you mentioned tail-ing, I'm expecting that you are comfortable with working on the terminal with CLI tools.

You can install awslogs locally and use it to tail Cloudwatch.

e.g.

$ awslogs get /aws/lambda/my-api-lambda ALL --watch --profile production

Aside from not needing to refresh anything anymore (that's what tail is for), I also like that you don't have to worry about jumping between different LogGroups (unlike in the CloudWatch console).




回答2:


Aside: We've noticed that tailing logs gets really slow after an AWS Lambda Function has had a lot of invocations. Even looking at logs through the AWS Console is incredibly slow. This is because "tail" type utilities need to connect to each log stream. Log events get expired due to the policy you set on the Log Group itself, but the Log Streams never get cleaned up. I made a few little utility scripts to help with that:

https://github.com/four43/aws-cloudwatch-log-clean

Hopefully that save you some agony over waiting for those logs.




回答3:


Actually, there is a better way with Insights (in the same CloudWatch).

Run query like on a log group and you will get what you want:

fields @timestamp, @message
| sort @timestamp desc
| limit 20

You can also add it to Dashboard to always have it "nearby"



来源:https://stackoverflow.com/questions/47847537/tailing-aws-lambda-cloudwatch-logs

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