英文:
Filtering aws logs via python cdk - filter log pattern errors
问题
我能够在CloudWatch日志中运行查询,没有问题...
filter eventName = 'SomeEvent' and responseElements.someId in ['string1', 'string2']
现在我正在尝试在Python中复制相同的操作,因为我必须为许多ID执行此操作。
通过...
result = cw.filter_log_events(
logGroupName='/some-log-group',
startTime=start_time,
endTime=end_time,
filterPattern=filter_pattern,
limit=1000
)
其中过滤模式如下定义。
这个有效...
filter_pattern = { $.name = "SomeName" }
这个无效...
ids = ['string1','string2','string3']
ids_pattern = '|'.join(ids)
filter_pattern = f'{{ $.name = "SomeName" && $.responseElements.someId like /{ids_pattern}/ }}'
这个也无效...
ids = ['string1','string2','string3']
ids_pattern = ','.join(ids)
filter_pattern = f'{{ $.name = "SomeName" && $.responseElements.someId in [{ids_pattern}] }}'
错误 - 调用FilterLogEvents操作时: 无效的过滤模式
文档链接在这里...
https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html
不清楚是否支持like
或in
,但想知道是否这是问题的原因?
英文:
I am able to run a query in CloudWatch logs with no issues...
filter eventName = 'SomeEvent' and responseElements.someId in ['string1', 'string2']
I am now trying to replicate the same in python because I have to do this for many ids.
via...
result = cw.filter_log_events(
logGroupName='/some-log-group',
startTime=start_time,
endTime=end_time,
filterPattern=filter_pattern,
limit=1000
)
where the filter patterns are defined below.
This works...
filter_pattern = { $.name = "SomeName" }
This does not...
ids = ['string1','string2','string3']
ids_pattern = '|'.join(ids)
filter_pattern = f'{{ $.name = "SomeName" && $.responseElements.someId like /{ids_pattern}/ }}'
Nor does this...
ids = ['string1','string2','string3']
ids_pattern = ','.join(ids)
filter_pattern = f'{{ $.name = "SomeName" && $.responseElements.someId in [{ids_pattern}] }}'
Error - when calling the FilterLogEvents operation: Invalid filter pattern
Documentation here...
https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html
Does not make it clear if either like
or in
is supported but wondering if this is the issue?
答案1
得分: 0
糟糕的文档,因为似乎不支持in
或like
,而错误没有帮助解决这个问题。
改为...
{ $.name = "SomeName" && ($.responseElements.someId = "string1" || $.responseElements.someId = "string2") }
英文:
Bad documentation since it looks like in
or like
may not be supported while the errors do nothing to help figure that out.
Instead went with...
{ $.name = "SomeName" && ($.responseElements.someId = "string1" || $.responseElements.someId = "string2") }
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论