Contents

View AWS CLI logs in Real-Time

Almost traditional log viewing in the AWS Console, but in real-time on your terminal!

How to tail AWS CLI logs

After installing the aws-cli on your machine, you can start tailing your logs in real-time among other AWS services. The primary use of the command requires you to specify the log group and log stream.

An example of the command is:

1
aws logs tail "/aws/lambda/slack_event_handler"

–follow (tail -f)

In order to tail the 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.

An example of the command is:

1
aws logs tail "/aws/lambda/slack_event_handler" --follow
Results:

–format

By default, the logs tail command prints the following:

  • timestamp and timezone
  • log stream name
  • log messages

For a more readable version, set the --format parameter to short. ( The current options are detailed and short, It defaults to detailed)

An example of the command is:

1
aws logs tail "/aws/lambda/slack_event_handler" --follow --format short
Results:

–since

The aws logs tail command also enables us to view the generated logs of a CloudWatch log group for a specific time period. By default the command returns the logs from the past 10 minutes.

To return the logs from a specific time period, use the --since parameter: An example of the commands are:

1
2
3
4
5
aws logs tail "/aws/lambda/slack_event_handler" --follow --since 10s
aws logs tail "/aws/lambda/slack_event_handler" --follow --since 30m
aws logs tail "/aws/lambda/slack_event_handler" --follow --since 3h
aws logs tail "/aws/lambda/slack_event_handler" --follow --since 2d
aws logs tail "/aws/lambda/slack_event_handler" --follow --since 3w

–filter-pattern (grep)

You can filter which log messages the aws logs tail commands displays to your terminal, by using the --filter-pattern parameter. The following example only returns log messages that include the string Hello.

An example of the command is:

1
aws logs tail "/aws/lambda/slack_event_handler" --follow --format short --filter-pattern "NoneType"
Results:

This is a tip
To filter for multiple strings, simply prefix them with a ? character.

References