每次在名为“mybucket”的 S3 存储桶中创建 S3 对象时,我想通过 EventBridge 触发 AWS lambda 函数,但前提是其名称/密钥以“.csv”后缀结尾并且是在该存储桶的“in”文件夹。 我目前拥有的 EventBridge 规则是这样的:
{
"detail-type": ["Object Created"],
"source": ["aws.s3"],
"detail": {
"bucket": {
"name": ["mybucket"]
},
"object": {
"key": [{
"suffix": ".csv"
}, {
"prefix": "in/"
}]
}
}
}
我实际上希望这个规则能够以正确的方式工作,但事实并非如此,相反,它的行为就像后缀和前缀过滤条件之间存在 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 ] } ]
}
}
OR 关系需要额外的 $or-syntax,如文档中给出的示例所示:
{
"detail": {
"$or": [
{ "c-count": [ { "numeric": [ ">", 0, "<=", 5 ] } ] },
{ "d-count": [ { "numeric": [ "<", 10 ] } ] },
{ "x-limit": [ { "numeric": [ "=", 3.018e2 ] } ] }
]
}
}
那么,为什么我的规则表现得好像后缀和前缀条件之间存在 OR 关系?我需要改变什么才能让它按照我想要的方式工作?
目前不可能
有两种方法可以设置“看起来像
and
运算符”并且不会引发语法错误的内容,但它们的工作方式有所不同:
"key": [{"prefix": "example/directory/"}],
"key": [{"suffix": ".png"}]
输入"key": "other/directory/image.png"
将是有效OR
运算符:
"key": [{"prefix": "example/directory/"}, {"suffix": ".png"}]
输入 "key": "other/directory/image.png"
和 "key": "example/directory/not_image.txt"
都将是 有效现在可以使用通配符,您只需更新您的
key
:
{
"detail-type": ["Object Created"],
"source": ["aws.s3"],
"detail": {
"bucket": {
"name": ["mybucket"]
},
"object": {
"key": [{
"wildcard": "in/*.csv"
}]
}
}
}
听起来正是我面临的问题。我在 IBM 文档中找到了一些内容:https://www.ibm.com/docs/en/dsm?topic=csqcson-forwarding-objectcreated-notifications-sqs-queue-by-using-amazon-eventbridge
他们说要重复按键
{
"source": ["aws.s3"],
"detail-type": ["Object Created"],
"detail": {
"bucket": {
"name": ["<example-bucket>"]
},
"object": {
"key": [{
"prefix": "example/directory/"
}],
"key": [{
"suffix": ".png"
}]
}
}
}
这是非常违反直觉的,甚至违背了 AWS 的文档。我还没试过。