python - 无法筛选 aws lambda 函数的 boto3 日志流

标签 python amazon-web-services aws-lambda boto3 amazon-cloudwatchlogs

我无法使用 boto3 API 和 'endtime' 过滤器过滤出 lambda 函数的 logStreams'logStreamNamePrefix'过滤器。

这有效:

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        
)

但这些没有:

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

最佳答案

作为临时修复,我正在轮询所有响应,然后明确过滤它。

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']))

关于python - 无法筛选 aws lambda 函数的 boto3 日志流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60275792/

相关文章:

mysql - 有没有办法在 AWS MySql/Aurora 上运行引用 sql 远程文件的远程 shell 脚本

amazon-web-services - 使用 Lambda 集成保护 AWS API 网关

javascript - aws-lambda 找不到模块

python - 使用关键字参数调用任务 block

python - 应该多久使用一次 Python 装饰器?

python - fork一次并获得不同的pid值

amazon-ec2 - EBS 与实例存储的优势(反之亦然)

python - 如何配置带有 Python 扩展的 Visual Studio Code 以不提示无法导入模块?

svn - 如何在 Amazon Auto-scaling 组中的多个 ec2 实例上部署和更新应用程序?

node.js - 运行 nodejs + expressjs 时访问 aws-lambda 上下文