Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to view aws log real time (like tail -f)

I can view the log using the following command.

aws logs get-log-events --log-group-name groupName --log-stream-name streamName --limit 100 

what is the command to get feature like tail -f so that i can see the log real time

like image 957
LynAs Avatar asked Dec 01 '15 11:12

LynAs


People also ask

Are CloudWatch logs real time?

You can use subscriptions to get access to a real-time feed of log events from CloudWatch Logs and have it delivered to other services such as an Amazon Kinesis stream, an Amazon Kinesis Data Firehose stream, or AWS Lambda for custom processing, analysis, or loading to other systems.

How do I view AWS logs?

To see your log data, sign in to the AWS Management Console, and open the CloudWatch console. In the left navigation pane, choose the Logs tab. Find your log group in the list of groups and open the log group. Your log group name is the Name that you set when you set up logging in the Amazon OpenSearch Service wizard.

Can you tail CloudWatch logs?

To tail your CloudWatch logs in real time, add the --follow parameter to the aws logs tail command. The command tails the logs for a specific CloudWatch log group. By setting the --follow parameter, the command continuously polls for new logs.


2 Answers

I was really disappointed with awslogs and cwtail so I made my own tool called Saw that efficiently streams CloudWatch logs to the console (and colorizes the JSON output):

You can install it on MacOS with:

brew tap TylerBrock/saw brew install saw 

It has a bunch of nice features like the ability to automatically expand (indent) the JSON output (try running the tool with --expand):

saw watch my_log_group --expand 

Got a Lambda you want to see error logs for? No Problem:

saw watch /aws/lambda/my_func --filter error  

Saw is great because the output is easily readable and you can stream logs from entire log group, not just a single stream in the group. Filtering and watching streams with a certain prefix is also just as easy!

like image 90
Tyler Brock Avatar answered Sep 25 '22 04:09

Tyler Brock


Note that tailing an aws log is now a supported feature of the official awscli, albeit only in awscli v2, which is not released yet. Tailing and following the logs (like tail -f) can now be accomplished by something like:

aws logs tail $group_name --follow 

To install the v2 version, see the instructions on this page. It was implemented in this PR. To see it demonstrated at the last re:Invent conference, see this video.

In addition to tailing the logs, it allows viewing the logs back to a specified time using the --since parameter, which can take an absolute or relative time

aws logs tail $group_name --since 5d 

To keep the v1 and v2 versions of awscli separate, I installed awscli v2 into a separate python virtual environment and activate it only when I need to use awscli v2.

like image 27
Anton I. Sipos Avatar answered Sep 22 '22 04:09

Anton I. Sipos