Reputation: 421
I am unable to filter out logStreams for lambda function using boto3 API, with 'endtime'
filter or 'logStreamNamePrefix'
filter.
This works:
client = boto3.client('logs',
aws_access_key_id=aws_account['access_key'],
aws_secret_access_key=aws_account['secret_key'],
region_name=region)
logGroupName = '/aws/lambda/' + function_name
response = client.filter_log_events(
logGroupName=logGroupName,
startTime=int((datetime(2020, 1, 15)- datetime(1970, 1, 1)).total_seconds()), # epoch_time
)
But these don`t:
1.
response = client.filter_log_events(
logGroupName=logGroupName,
startTime=int((datetime(2020, 1, 15)- datetime(1970, 1, 1)).total_seconds()), # epoch_time
endTime=int((datetime(2020, 1, 31)- datetime(1970, 1, 1)).total_seconds())
)
ERROR: Empty list is returned, although log data is there for the specified time range
2.
response = client.filter_log_events(
logGroupName=logGroupName,
startTime=int((datetime(2020, 1, 15)- datetime(1970, 1, 1)).total_seconds()), # epoch_time
logStreamNamePrefix='^2020/01' # logs starting with this prefix
)
ERROR:
botocore.exceptions.ParamValidationError: Parameter validation failed:
Unknown parameter in input: "logStreamNamePrefix", must be one of: logGroupName, logStreamNames, startTime, endTime, filterPattern, nextToken, limit, interleaved
Upvotes: 3
Views: 438
Reputation: 421
As a temporary fix, I am polling all the responses and then filtering it expilictly.
response = client.filter_log_events(
logGroupName=logGroupName,
startTime=int((datetime(2020, 1, 15)- datetime(1970, 1, 1)).total_seconds()), # epoch_time
)
filtered_response = list(filter(lambda x: x['logStreamName'].startswith('2020/01'), response['events']))
Upvotes: 1