如何将数据从 AWS IoT MQTT 代理推送到 S3 存储桶中的随机文件

How to push data from AWS IoT MQTT broker to a random file in S3 bucket

我创建了一个规则来转发发布到任何主题的所有消息,例如foo/bar 的 AWS IoT Core 托管 MQTT 代理到 S3 存储桶中的嵌套文件夹。为此,我使用 key 部分。我可以将数据发送到嵌套文件夹,如 a/b/c。问题是——它将 c 作为目标文件,并且该文件在新数据到达时得到更新。是否有任何配置可以让我在数据到达时将其放入新文件(具有任何随机名称)中的存储桶中(类似于我们将数据从 firehose 转发到 S3 时发生的情况)

您可以更改 key 以使用 newuuid() 功能。例如

a/b/${newuuid()}

这会将数据写入 a/b 文件夹中的文件,文件名是生成的 UUID。

AWS IoT S3 操作中的 key 允许您使用 IoT SQL 参考函数来形成文件夹和文件名。

documentation for the key 状态:

The path to the file where the data is written. For example, if the value of this argument is "${topic()}/${timestamp()}", the topic the message was sent to is "this/is/my/topic,", and the current timestamp is 1460685389, the data is written to a file called "1460685389" in the "this/is/my/topic" folder on Amazon S3.

如果您不想使用时间戳,那么您可以使用其他函数形成文件名,例如 random float (rand()), calculate a hash (md5()), a UUID (newuuid()) or the trace id of the message (traceid()).