AWS Lambda捕获物联网注册表事件 [英] AWS lambda capture IoT registry event

查看:117
本文介绍了AWS Lambda捕获物联网注册表事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划在AWS IoT注册表中生成新事物,一旦事物成功生成,就将事物arn,事物名称,证书信息写入AWS RDS数据库.

I'm plan to generate new thing in AWS IoT Registry and once the thing is generated successfully, write the thing arn, thing name, cert information into AWS RDS database.

是否可以使用lambda捕获IoT注册表事件并触发lambda写入数据库?

Is this possible to use lambda capture IoT registry event and trigger lambda to write into database?

有什么建议吗?

推荐答案

AWS IoT通过其自己的MQTT代理发布了许多事件.

AWS IoT publishes a lot of its events through it's own MQTT broker.

对于您而言,您对$aws/events/thing/<thingName>/created主题感兴趣(

In your case you're interested in the $aws/events/thing/<thingName>/created topic (https://docs.aws.amazon.com/iot/latest/developerguide/registry-events.html).

通过特定主题发送消息时,您可以使用AWS IoT规则引擎自动执行操作(

When messages are sent through certain topics you can use the AWS IoT Rule engine to automatically perform actions (https://docs.aws.amazon.com/iot/latest/developerguide/iot-rules.html).

这些动作可以是一个lambda(如果您在问题中所分享的内容之外还有更多逻辑),但是也有一个dynamodb规则,可以用来解决该问题而无需编写自己的自定义代码:

These actions could be a lambda (if you have more logic outside what you've shared in the question), but there's a dynamodb rule, too, which can be used to solve this problem without writing your own custom code:

  • DynamoDb rules: https://docs.aws.amazon.com/iot/latest/developerguide/iot-rule-actions.html#dynamodb-v2-rule
  • Lambda rules: https://docs.aws.amazon.com/iot/latest/developerguide/iot-rule-actions.html#lambda-rule

因此,在您的情况下,您可能会执行以下操作:

So in your case, you might do something like this:

{
  "sql": "SELECT thingId thingName timestamp FROM '$aws/events/thing/+/created'",
  "ruleDisabled": false,
  "awsIotSqlVersion": "2016-03-23",
  "actions": [{
    "dynamoDBv2": {
       "roleArn": "arn:aws:iam::123456789012:role/aws_iot_dynamoDBv2", 
       "putItem": {
         "tableName": "my_ddb_table"
        }
     }
  }]
}

不幸的是,似乎AWS并未将证书信息发布到注册主题.我的猜测是,这是因为证书和设备之间没有一对一的关系.

Unfortunately it seems like AWS does not publish the certificate information to a topic on registration. My guess is this is because there isn't a 1-to-1 relationship between certificate and device.

可以通过收听$aws/events/presence/connected/clientId主题来获取此信息;强制执行clientId === thingId(通常是这种情况),并从消息中记录principalIdentifier(

You can get this information by listening to the $aws/events/presence/connected/clientId topic; enforcing that the clientId === thingId (which is typically the case), and recording the principalIdentifier from the message (https://docs.aws.amazon.com/iot/latest/developerguide/life-cycle-events.html#connect-disconnect). You can once again automate this using AWS IoT rules.

这篇关于AWS Lambda捕获物联网注册表事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆