简体   繁体   English

可以将SQS消息属性添加到S3事件生成的SQS消息中吗?

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

I'd like to use AWS S3 to allow some users to add files to an S3 bucket. 我想使用AWS S3允许某些用户将文件添加到S3存储桶。

Then, I'd like to generate an SQS message when a new file has been added. 然后,我想在添加新文件时生成SQS消息。

Last, I'd like to consume the SQS message and process it with a background job worker of a particular class. 最后,我想使用SQS消息并与特定类的后台作业工人一起对其进行处理。

I'd like to use SQS message attributes to determine which background job worker class I should use for processing. 我想使用SQS消息属性来确定应使用哪个后台作业工人类进行处理。 As the SQS message attribute documentation states: 如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. 消息的使用者可以使用消息属性来帮助决定如何处理消息,而不必首先处理消息正文。

(via the SQS Developer Guide ) (通过SQS开发人员指南

However, under the S3 bucket's Properties, under Advanced Settings, the Events settings do not appear to expose a way to set message attributes. 但是,在S3存储桶的“属性”下的“高级设置”下,“事件”设置并未显示出公开消息属性的方法。

Is there a way to specify message attributes on an event-by-event basis for events generated from S3? 是否有一种方法可以针对S3生成的事件逐个事件地指定消息属性?

You should use a Lambda to add messages to the queue, for example with python using BOTO 3 API. 您应该使用Lambda将消息添加到队列中,例如使用BOTO 3 API的python。 Map this Lambda to the S3 Event. 将此Lambda映射到S3事件。 http://docs.aws.amazon.com/lambda/latest/dg/with-s3.html http://docs.aws.amazon.com/lambda/latest/dg/with-s3.html

There is not a way to inject custom message attributes into S3 event notifications... but also note that you may be misinterpreting what message attributes can be used for. 没有将自定义消息属性注入S3事件通知中的方法...但是也请注意,您可能会误解可用于什么消息属性。

Message attributes [...] can be used by the consumer of the message 消息的使用者可以使用消息属性

This means they provide a mechanism for the consumer to triage a message after the consumer has already received it from the queue. 这意味着它们为使用者提供了一种机制,在使用者已经从队列中接收到消息之后,便可以对消息进行分类。

You can't selectively consume messages based on message attributes. 您不能根据消息属性有选择地使用消息。 Queue consumers receive the next available message(s) when they poll the queue. 队列使用者在轮询队列时会收到下一条可用消息。 They don't get to select which messages they consume. 他们没有选择他们消费的消息。

If you want to divide the messages up by class, you'll need an intermediate process that selectively distributes messages to the appropriate (separate) downstream queues. 如果要按类别划分消息,则需要一个中间过程,该过程有选择地将消息分发到适当的(单独的)下游队列。 Better, if your structure allows it, might be different event configurations matching specific patterns that need to go to individual queues. 更好的是,如果您的结构允许的话,可能是与需要进入各个队列的特定模式匹配的不同事件配置。

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

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