Reputation: 5142
I am using AWS Lambda for my application. For logs, I have to see in UI only, which I really don't like to see. Is there a way that I could connect to Cloudwatch logs locally and then see the logs by the tail command? Or if I could access Cloudwatch server to see logs? Basically, I wanted to see logs on my terminal. If there is any way to do that, please let me know.
Thanks for your help.
Upvotes: 6
Views: 4826
Reputation: 52433
You can use AWS CLI to get your logs in real time. See: get-log-events
AWS doesn't provide a functionality where you can tail the log. There are few 3rd party tools you can use. I have used jorgebastida/awslogs which was sufficient for my needs.
Update 02/25/2021: Thanks to @adavea, I just checked and found AWS has added a new feature to tail the CW logs.
--follow
(boolean) Whether to continuously poll for new logs.
Upvotes: 10
Reputation: 481
On my linux/macosx/cygwin console, this will give you the latest log file.
Substitute $1 with your group name
echo aws logs get-log-events --log-group-name /aws/lambda/$1 --log-stream-name `aws logs describe-log-streams --log-group-name /aws/lambda/$1 --max-items 1 --descending --order-by LastEventTime | grep logStreamName | cut -f2 -d: | sed 's/,//'|sed 's/\"/'\''/g'`| sh -
Note that you will need to install awscli (https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html)
I wrapped the above in a sh function
function getcw() {
echo aws logs get-log-events --log-group-name /aws/lambda/$1 --log-stream-name `aws logs describe-log-streams --log-group-name /aws/lambda/$1 --max-items 1 --descending --order-by LastEventTime | grep logStreamName | cut -f2 -d: | sed 's/,//'|sed 's/\"/'\''/g'`| sh -
}
and can view the latest log for my logs in chai-lambda-trigger using the command
$ getcw chai-lambda-trigger
If you wanted just the tail of the output, you could do
$ getcw chai-lambda-trigger | tail
Upvotes: 2
Reputation: 3086
There are some command line tools like cwtail and awslogs that do a -f follow tail.
Your other option is a free tool I created called SenseLogs that does a live tail in your browser. It is 100% browser based. See https://github.com/sensedeep/senselogs/blob/master/README.md for details.
Upvotes: 1