我正在使用下面的链接来实现AWS IoT的准时配置(JITP)。
https://aws.amazon.com/blogs/iot/setting-up-just-in-time-provisioning-with-aws-iot-core/
如果我使用这个链接中提供的默认策略,我就能够成功地注册这个东西。对于第一个mosquitto_pub调用,我得到连接丢失的错误,随后的调用成功,在AWS IoT中成功地创建了这个东西。
我希望从证书中提取其他属性,例如OrganizationalUnit,并希望将它作为属性添加到事物中。
因此,我修改了供应模板,以包括这个属性,它没有工作。所有对mosquitto_pub的调用都会导致连接丢失。
下面是我使用的配置模板字符串-
{
"Parameters": {
"AWS::IoT::Certificate::Country": {
"Type": "String"
},
"AWS::IoT::Certificate::CommonName": {
"Type": "String"
},
"AWS::IoT::Certificate::Id": {
"Type": "String"
},
"AWS::IoT::Certificate::OrganizationalUnit": {
"Type": "String"
}
},
"Resources": {
"thing": {
"Type": "AWS::IoT::Thing",
"Properties": {
"ThingName": {
"Ref": "AWS::IoT::Certificate::CommonName"
},
"ThingGroups": [{
"Ref": "AWS::IoT::Certificate::OrganizationalUnit"
}],
"AttributePayload": {
"version": "v1",
"country": {
"Ref": "AWS::IoT::Certificate::Country"
},
"customerid": {
"Ref": "AWS::IoT::Certificate::OrganizationalUnit"
}
}
}
},
"certificate": {
"Type": "AWS::IoT::Certificate",
"Properties": {
"CertificateId": {
"Ref": "AWS::IoT::Certificate::Id"
},
"Status": "ACTIVE"
}
},
"policy": {
"Type": "AWS::IoT::Policy",
"Properties": {
"PolicyDocument": "{\"Version\": \"2012-10-17\",\"Statement\": [{\"Effect\":\"Allow\",\"Action\": [\"iot:Connect\"],\"Resource\" : \"arn:aws:iot:*:*:client\/${iot:Connection.Thing.ThingName}\"},{\"Effect\":\"Allow\",\"Action\": [\"iot:Receive\",\"iot:Subscribe\",\"iot:Publish\"],\"Resource\" : \"arn:aws:iot:*:*:topic\/${iot:Connection.Thing.ThingName}\/*\"}]}"
}
}
}
}我们还确保存在具有所需名称的ThingGroups。
有什么指示吗?
发布于 2020-06-10 01:05:51
我在你的岗位上试图为自己解决这个问题。我不知道这对你有什么用,但我有两条评论:
正确的顺序:
我发现我必须在注册证书之前创建ThingGroups和ThingTypeName,尽管没有这样做并没有返回任何错误。我注意到您已经这样做了,但是请确保您没有更改任何组名或类型名(我心不在焉地做了,它刺痛了我)。
特别是,当我首先使用aws iot register-ca-certificate (配置模板中的ThingGroups & ThingTypeName ),然后创建组和类型,最后开始连接设备时,它没有工作。我的建议是仔细地重新开始,然后按照顺序进行检查:创建组和类型;注册ca cert。然后尝试连接。
策略格式:
作为起点,我对策略资源使用了以下格式。*用于隔离格式问题的来源。我发现直接在IoT控制台中编辑策略JSON文件是找出问题所在的最有效的方法。
对于物联网:发布,物联网:接收&物联网:订阅,资源=
"arn:aws:iot:ap-southeast-2:123456789012:*/things/${iot:Connection.Thing.ThingName}/* 对于物联网:连接,资源=
"arn:aws:iot:ap-southeast-2:123456789012:*/${iot:Connection.Thing.ThingName}在这样做之后,JITP进程开始工作。祝你好运。
https://stackoverflow.com/questions/55124202
复制相似问题