I am working with Python 3.6 and boto3==1.7.84. I was trying to fetch CloudWatch logs with boto3 from AWS, but found that the number of events returned is much less than what I can see in the CloudWatch insights page. I supposed that
import boto3
client = boto3.client('logs')
response = client.filter_log_events(
logGroupName='/aws/batch/job',
startTime=1572520000000,
endTime=1572570000000,
filterPattern='exceptions',
)
would return all the events including 'exceptions' regardless of the job stream name. However it returned nothing. But if I specified the logStreamNames like this
import boto3
client = boto3.client('logs')
response = client.filter_log_events(
logGroupName='/aws/batch/job',
logStreamNames=['training/default/[ASpecificID]'],
startTime=1572520000000,
endTime=1572570000000,
filterPattern='exceptions',
)
it did return the logs containing string 'exceptions' with logStreamNames=['training/default/[ASpecificID]']
.
The other weird thing was that when I did
import boto3
client = boto3.client('logs')
response = client.filter_log_events(
logGroupName='/aws/batch/job',
logStreamNamePrefix='training/default',
startTime=1572520000000,
endTime=1572570000000,
filterPattern='exceptions',
)
the logs containing string 'exceptions' with logStreamNames=['training/default/[ASpecificID]']
were not returned. Some logs with logStreamNamePrefix='training/'
did show up, but not all. The number of events returned is much less than what I got by doing
fields @timestamp, @message, @logStream
| filter @logStream like /training\/default/
| filter @message like /exceptions/
| limit 10000
with CloudWatch logs insights query syntax in the CloudWatch insights page. Did I do anything wrong with boto3 that led to this discrepancy?