We have a server that runs this piece of code:
region = settings.AWS_REGION
client = boto3.client('logs', region_name=region)
job_id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
response = client.get_log_events(
logGroupName=f'/proprietary/log/group/name',
logStreamName=job_id,
startTime=0,
startFromHead=False, # the latest log events are returned first.
)
The response is sometimes, but not always, empty. An example of an empty response is:
{'events': [], 'nextForwardToken': 'f/xxxxxxxx/s', 'nextBackwardToken': 'b/xxxxxxxx/s', 'ResponseMetadata': {'RequestId': 'xxxxxxxx', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': 'xxxxxxxx, 'content-type': 'application/x-amz-json-1.1', 'content-length': 'xxxxxxxx', 'date': 'Fri, 13 Oct 2023 14:55:41 GMT'}, 'RetryAttempts': 0}}
However, if I go to the log group and stream name associated with /proprietary/log/group/name and job_id, I do see a stream of results.
Other posts suggested running this code
list_resp = client.list_metrics()
but it's not available to run with the client
Another post suggested It's a permissions issue. But I'm using the same permissions to view the log stream in AWS console as I'm using to run this code.
Is the code wrong or is this a bug?
Interesting! This is very helpful, thanks! I'm trying it and will accept if it works
So I've passing the nextForwardToken into the boto3 call several times in a row, more than 5 times, and still getting empty responses every time. It's unclear how many times I would have to loop through the while loop to get something. Furthermore, the while loop would just spin forever if there actually were no events.
I'm having a similar issue, where some of my logs streams can be returned just fine, but others, which have the same number of log entries, just return an empty array, [].
EDIT1: Came back this morning after the weekend and now everything works. (?????) EDIT2: A solution that seems to work is adding 'startTime' and 'endTime'. Also I have no issues if I use 'startFromHead=True'. It seems to be a bug with 'startFromHead=False', see https://github.com/boto/boto3/issues/3718