简体   繁体   English

如何将相同的Amazon S3事件定向到几个不同的SQS队列中?

[英]How to direct the same Amazon S3 events into several different SQS queues?

I'm working with AWS Lambda functions (in Python), that process new files that appear in the same Amazon S3 bucket and folders. 我正在使用AWS Lambda函数(在Python中),该函数处理出现在相同Amazon S3存储桶和文件夹中的新文件。

When new file appears in s3:/folder1/folderA, B, C , an event s3:ObjectCreated:* is generated and it goes into sqs1 , then processed by Lambda1 (and then deleted from sqs1 after successful processing). 当新文件出现在s3:/folder1/folderA, B, C ,将生成事件s3:ObjectCreated:*并进入sqs1 ,然后由Lambda1处理(成功处理后从sqs1删除)。

I need the same event related to the same new file that appears in s3:/folder1/folderA (but not folderB, or C) to go also into sqs2 , to be processed by Lambda2 . 我需要与出现在s3:/folder1/folderA (但不是folderB或C)中的同一新文件相关的相同事件,也要进入sqs2 ,由Lambda2处理。 Lambda1 modifies that file and saves it somewhere, Lambda2 gets that file into DB, for example. Lambda1修改该文件并将其保存在某个位置,例如, Lambda2将该文件保存到DB中。

But AWS docs says that: 但是AWS文档说:

Notification configurations that use Filter cannot define filtering rules with overlapping prefixes, overlapping suffixes, or prefix and suffix overlapping. 使用筛选器的通知配置不能定义前缀重叠,后缀重叠或前缀和后缀重叠的过滤规则。

So question is how to bypass this limitation? 那么问题是如何绕过这个限制? Are there any known recommended or standard solutions? 是否有已知的推荐或标准解决方案?

It appears that your requirement is: 看来您的要求是:

  • When a file is added to folderA , you wish to send a message to sqs1 AND sqs2 (can be done in parallel) 将文件添加到folderA ,您希望将消息发送到sqs1 sqs2 (可以并行执行)
  • When a file is added to folderB , you wish to send a message to sqs2 将文件添加到folderB ,您希望将消息发送到sqs2

This can be done by configuring separate events for each folder : 这可以通过为每个文件夹配置单独的事件来完成:

  • Event A: Prefix = folderA 事件A: Prefix = folderA
  • Event B: Prefix = folderB 事件B: Prefix = folderB
  • Event C: Prefix = folderC 事件C: Prefix = folderC

You can then use an Amazon SNS topic to fan-out to multiple queues: 然后,您可以使用Amazon SNS主题扇出多个队列:

eventA -> sns1 +-> sqs1 -> Lambda1
               |
               +-> sqs2 -> Lambda2

eventB -> sqs1 -> Lambda1

eventC -> sqs1 -> Lambda1

Instead of set up the S3 object notification of (S3 -> SQS), you should set up a notification of (S3 -> Lambda). 代替设置(S3-> SQS)的S3对象通知,您应该设置(S3-> Lambda)的通知。

In your lambda function, you parse the S3 event and then you write your own logic to send whatever content about the S3 event to whatever SQS queues you like. 在lambda函数中,您解析S3事件,然后编写自己的逻辑,以将有关S3事件的任何内容发送到所需的任何SQS队列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM