in client/iot_client.py [0:0]
def init_thing_with_boto(self):
"""
This provisioning flow can register a thing directly with IoT Core if the client already has AWS credentials.
This is primarily for demo purposes
:return:
Certificate
"""
boto_iot_client = boto3.client('iot')
print("Retrieving certificate")
certificate_data = boto_iot_client.create_certificate_from_csr(
certificateSigningRequest=self.csr.decode('utf-8'),
setAsActive=True
)
print(certificate_data['certificatePem'].splitlines())
f = open("iot_provisioning_template.json", "r")
provisioning_template_string = f.read()
prov_template_object = json.loads(provisioning_template_string)
prov_template_object['Resources']['policy']['Properties']['PolicyName'] = os.environ['IOT_POLICY_NAME']
boto_iot_client.register_thing(
templateBody=json.dumps(prov_template_object),
parameters={
"SerialNumber": self.serial_number,
"AWS::IoT::Certificate::Id": certificate_data['certificateId']
}
)
return certificate_data['certificatePem']