jim*_*eus 5 rules pattern-matching amazon-web-services suffix aws-event-bridge
每次在名为“mybucket”的 S3 存储桶中创建 S3 对象时,我想通过 EventBridge 触发 AWS lambda 函数,但前提是其名称/密钥以“.csv”后缀结尾并且是在“”中创建的在该存储桶的“文件夹中。我目前拥有的 EventBridge 规则是这样的:
{
"detail-type": ["Object Created"],
"source": ["aws.s3"],
"detail": {
"bucket": {
"name": ["mybucket"]
},
"object": {
"key": [{
"suffix": ".csv"
}, {
"prefix": "in/"
}]
}
}
}
Run Code Online (Sandbox Code Playgroud)
我实际上希望这个规则能够以正确的方式工作,但事实并非如此,相反,它的行为就像后缀和前缀过滤条件之间存在 OR 关系一样。据我了解AWS文档(https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns-content-based-filtering.html#eb-filtering-complex-example)上述规则应定义后缀和前缀过滤条件之间的 AND 关系,类似于文档中给出的示例:
{
"time": [ { "prefix": "2017-10-02" } ],
"detail": {
"state": [ { "anything-but": "initializing" } ],
"c-count": [ { "numeric": [ ">", 0, "<=", 5 ] } ],
"d-count": [ { "numeric": [ "<", 10 ] } ],
"x-limit": [ { "anything-but": [ 100, 200, 300 ] } ]
}
}
Run Code Online (Sandbox Code Playgroud)
而 OR 关系需要额外的 $or-syntax,如文档中给出的示例所示:
{
"detail": {
"$or": [
{ "c-count": [ { "numeric": [ ">", 0, "<=", 5 ] } ] },
{ "d-count": [ { "numeric": [ "<", 10 ] } ] },
{ "x-limit": [ { "numeric": [ "=", 3.018e2 ] } ] }
]
}
}
Run Code Online (Sandbox Code Playgroud)
那么,为什么我的规则表现得好像后缀和前缀条件之间存在 OR 关系?我需要改变什么才能让它按照我想要的方式工作?
小智 2
目前这是不可能的
有两种方法可以设置“看起来像and运算符”并且不会引发语法错误的内容,但它们的工作方式有所不同:
"key": [{"prefix": "example/directory/"}],
"key": [{"suffix": ".png"}]
Run Code Online (Sandbox Code Playgroud)
输入"key": "other/directory/image.png"有效OR:
"key": [{"prefix": "example/directory/"}, {"suffix": ".png"}]
Run Code Online (Sandbox Code Playgroud)
两个输入"key": "other/directory/image.png"和"key": "example/directory/not_image.txt"都有效有关更多信息,请参阅 AWS EventBridge 文档的基于内容的过滤和数组页面