Assuming you have LOG_GROUP_NAME
and STREAM_NAME
as environment variables, you can run the following:
aws logs get-log-events --log-group-name "$LOG_GROUP_NAME" --log-stream-name "$STREAM_NAME" | yq -o=json | jq '.events[] | .timestamp, .message' > stream.log
The log entries with timestamp
and message
will now be in the file stream.log
Another way to format the output (prevent splitting lines for timestamp and message fields):
aws logs get-log-events --log-group-name "$LOG_GROUP_NAME" --log-stream-name "$STREAM_NAME" | yq -o=json | jq '.events[] | "\(.timestamp) \(.message)"'
Alternatively, to get the last hour:
aws logs tail $LOG_GROUP_NAME --since 1h
Or follow (similar to tail -f
):
aws logs tail $LOG_GROUP_NAME --since 1h --follow