aws-lambda - 避免轮询和长时间运行的 lambda 任务
问题描述
我有一个 cloudwatch 组来监控我的应用程序启动的次数。然后我写了一个 Lamba 函数,它应该每 24 小时在 python 中使用 boto3 检索这些日志。为此,我启动一个查询,然后轮询 get_query_results 方法以查看它是否已完成。但是,这给我留下了一个使用大量资源的非常糟糕的实现。
有没有更好的方法来使用某种回调来做到这一点?
query_id = cloudwatch_connector.start_query('fields @timestamp, @message|filter @message like /APPSTART/').get('queryId')
# Wait until it is completed
running = True
while running:
response = cloudwatch_connector.get_query_results(query_id)
status = response.get('status')
if status == 'Complete':
print("Done gathering logs")
print(response)
running = False
if status == 'Failed' or status == 'Cancelled':
raise Exception('Request either failed or was cancelled')
time.sleep(1000)
我真正想做的是每晚 00:00 运行 Insights 查询并将其保存到文本文件中
解决方案
推荐阅读
- oracle - 表列表以及关键信息 - Oracle
- amazon-web-services - MaxConcurrency 属性如何用于 AWS Step Functions 中的 Map 任务?
- flutter - Flutter:根据移动/平板设备类型更改主题数据
- angular - 将服务实例传播到对话组件未按预期工作
- fortran - Fortran 从变量定义参数
- javascript - 试图进行平滑滚动,但 JS 中出现错误
- javascript - 强制 JavaScript 方法在迭代中使用类的属性而不是当前对象的属性
- javascript - 如何将类包装在高阶组件中?
- twitter-bootstrap - 轮播标题不会在移动设备上覆盖图像
- java - 如何检查字符串中的单词或短语并将其与单词或短语数组进行比较?