american-ninja-warrior
american-ninja-warrior

Reputation: 8177

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)

Upvotes: 11

Views: 6536

Answers (4)

Peter Arboleda
Peter Arboleda

Reputation: 521

If you are using the awscli

From the command line you can also do:

aws logs tail <your_log_group_name> --follow

The --follow flag will pull for new logs continuously

You can also use --since to set from what time to begin displaying logs

It supports:

s - seconds

m - minutes

h - hours

d - days

w - weeks

i.e

aws logs tail <your_log_group_name> --since 20m

Upvotes: 2

lapkritinis
lapkritinis

Reputation: 2814

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"

Upvotes: 0

four43
four43

Reputation: 1750

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.

Upvotes: 2

Noel Llevares
Noel Llevares

Reputation: 16037

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

Upvotes: 15

Related Questions