AWS将MQTT消息存储到DynamoDB [英] AWS store MQTT message to DynamoDB
问题描述
我构建了一个Python脚本,该脚本定期发送MQTT消息.
I built a python script that sends MQTT message periodically.
这是发送到后端的JSON字符串:
This is the JSON string sent to the backend:
{"Id": "1234", "Ut": 1488395951, "Temp": 22.86, "Rh": 48.24}
在后端,我想将MQTT消息存储到DynamoDB表中.
On backend side, I want to store the MQTT message into DynamoDB table.
我遵循了Amazon教程,并且MQTT消息中包含的数据存储在表中.
I followed an Amazon tutorial and the data contained into the MQTT messages are stored into the table.
我的问题与表格列有关.
My problem regards the table columns.
该表格只有3个列:
- Id:分区键
- 提示:排序键
- 有效负载:包含mqtt消息.
是否可以为MQTT消息中包含的每个键设置列?
It is possible to have columns for each key contained into MQTT message?
我将有以下专栏: - ID -t -温度 -Rh
I would have this columns: - Id - Ut - Temp - Rh
感谢您的帮助!
推荐答案
我假设您正在尝试提出一个IoT网关规则,将您的消息存储在DynamoDB表中.不幸的是,IoT规则不允许将数据存储在多列中-您只能将有效负载(或其子集)存储在单列中.当前尚无规定将有效载荷中的属性提取到几个不同的列中.
I assume you're trying to come up with an IoT Gateway rule storing your message in a DynamoDB table. Unfortunately the IoT rules do not allow to store data in multiple columns - you can only store the payload (or a subset thereof) in a single column. There is currently no provision to extract properties from the payload into several different columns.
解决此问题的唯一方法(到目前为止,我已经发现)是通过IoT规则调用lambda函数,该规则运行的代码与其他答案所显示的类似.
The only way around this (which I've found so far) is to call a lambda function through the IoT rules which runs code similar to what the other answers have shown.
这篇关于AWS将MQTT消息存储到DynamoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!