能否将 SQS 消息属性添加到 S3 事件生成的 SQS 消息中?

Can you add SQS message attributes to SQS messages generated by S3 events?

我想使用 AWS S3 来允许一些用户将文件添加到 S3 存储桶。

然后,我想在添加新文件时生成一条 SQS 消息。

最后,我想使用 SQS 消息并使用特定 class 的后台工作人员处理它。

我想使用 SQS 消息属性来确定我应该使用哪个后台作业工作者 class 进行处理。正如 SQS 消息属性文档所述:

Message attributes [...] can be used by the consumer of the message to help decide how to handle the message without having to first process the message body.

(通过 SQS Developer Guide

但是,在 S3 存储桶的属性下,在高级设置下,事件设置似乎没有公开设置消息属性的方法。

有没有办法为从 S3 生成的事件逐个指定消息属性?

您应该使用 Lambda 将消息添加到队列中,例如 python 使用 BOTO 3 API。将此 Lambda 映射到 S3 事件。 http://docs.aws.amazon.com/lambda/latest/dg/with-s3.html

没有办法将自定义消息属性注入 S3 事件通知...但也请注意,您可能误解了消息属性的用途。

Message attributes [...] can be used by the consumer of the message

这意味着它们为消费者提供了一种机制,可以在消费者 已经从队列中收到消息后对其进行分类。

您不能select根据消息属性有效地使用消息。队列消费者在轮询队列时会收到下一条可用消息。他们不知道 select 他们使用了哪些消息。

如果您想将消息按 class 划分,您将需要一个中间进程来 select 将消息主动分发到适当的(单独的)下游队列。更好的是,如果您的结构允许,可能是不同的事件配置匹配需要转到各个队列的特定模式。