Last updated: Feb 26, 2024
Reading time·2 min
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.
The following example shows how to tail the logs of a lambda function using the AWS CLI.
aws logs tail "/aws/lambda/your-lambda-name" --follow
The syntax of the command looks as follows.
aws logs tail "YOUR_LOG_GROUP_NAME" --follow
By default, the logs tail command prints the:
For a more readable version, set the --format
parameter to short
.
aws logs tail "/aws/lambda/your-lambda-name" --follow --format short
The short version prints only the timestamp and the log messages.
The aws logs tail
command also enables us to view the generated logs of a
CloudWatch log group for a specific time period.
To return the logs from a specific time period, use the --since
parameter:
# Display the logs from the past 30 minutes aws logs tail "/aws/lambda/your-lambda-name" --follow --since 30m # Display the logs from the past 10 seconds aws logs tail "/aws/lambda/your-lambda-name" --follow --since 10s # Display the logs from the past 3 hours aws logs tail "/aws/lambda/your-lambda-name" --follow --since 3h # Display the logs from the past 2 days aws logs tail "/aws/lambda/your-lambda-name" --follow --since 2d # Display the logs from the past 3 weeks aws logs tail "/aws/lambda/your-lambda-name" --follow --since 3w
You can filter which log messages the aws logs tail
command displays to your
terminal, by using the --filter-pattern
parameter.
The following example only returns log messages that include the string Hello
.
aws logs tail "/aws/lambda/your-lambda-name" --follow --format short --filter-pattern "Hello"
The following example returns log messages that include the string Hello
OR
the string END
.
aws logs tail "/aws/lambda/your-lambda-name" --follow --format short --filter-pattern "?Hello ?END"
?
character.You can read more about the filter syntax for the aws logs tail
command by
going to the
docs.
You can learn more about the related topics by checking out the following tutorials: