Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tailing aws lambda/cloudwatch logs

Found out how to access lambda logs from another answer

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

like image 442
american-ninja-warrior Avatar asked Dec 16 '17 16:12

american-ninja-warrior


2 Answers

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).

like image 116
Noel Llevares Avatar answered Sep 22 '22 19:09

Noel Llevares


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.

like image 36
four43 Avatar answered Sep 20 '22 19:09

four43