3737logger = logging .getLogger ()
3838logger .setLevel ("INFO" )
3939
40- iot_client = boto3client ('iot' )
41-
4240error_messages = {
4341 100 : "d" ,
4442}
4846
4947# Verify that the certificate is in IoT Core
5048def get_certificate (certificateId ):
49+ iot_client = boto3client ('iot' )
5150 try :
5251 response = iot_client .describe_certificate (certificateId = certificateId )
5352 return response ["certificateDescription" ].get ("certificateId" )
@@ -57,6 +56,7 @@ def get_certificate(certificateId):
5756
5857# Retrieve the certificate Arn.
5958def get_certificate_arn (certificateId ):
59+ iot_client = boto3client ('iot' )
6060 try :
6161 response = iot_client .describe_certificate (certificateId = certificateId )
6262 return response ["certificateDescription" ].get ("certificateArn" )
@@ -65,6 +65,7 @@ def get_certificate_arn(certificateId):
6565 return None
6666
6767def get_thing (thingName ):
68+ iot_client = boto3client ('iot' )
6869 try :
6970 response = iot_client .describe_thing (thingName = thingName )
7071 return response .get ("thingArn" )
@@ -73,6 +74,7 @@ def get_thing(thingName):
7374 return None
7475
7576def get_policy (policyName ):
77+ iot_client = boto3client ('iot' )
7678 try :
7779 response = iot_client .get_policy (policyName = policyName )
7880 return response .get ('policyArn' )
@@ -87,6 +89,8 @@ def get_policy(policyName):
8789 return None
8890
8991def get_thing_group (thingGroupName ):
92+ iot_client = boto3client ('iot' )
93+
9094 try :
9195 response = iot_client .describe_thing_group (thingGroupName = thingGroupName )
9296 return response .get ('thingGroupArn' )
@@ -101,6 +105,7 @@ def get_thing_group(thingGroupName):
101105 return None
102106
103107def get_thing_type (typeName ):
108+ iot_client = boto3client ('iot' )
104109 try :
105110 response = iot_client .describeThingType (thingTypeName = typeName )
106111 return response .get ('thingTypeArn' )
@@ -115,10 +120,12 @@ def get_thing_type(typeName):
115120 return None
116121
117122def process_policy (policyName , certificateId ):
123+ iot_client = boto3client ('iot' )
118124 iot_client .attach_policy (policyName = policyName ,
119125 target = get_certificate_arn (certificateId ))
120126
121127def process_thing (thingName , certificateId , thingTypeName ):
128+ iot_client = boto3client ('iot' )
122129 certificateArn = get_certificate_arn (certificateId )
123130 try :
124131 response = iot_client .describe_thing (thingName = thingName )
@@ -159,7 +166,7 @@ def get_certificate_fingerprint(certificate: x509.Certificate):
159166 return binascii .hexlify (certificate .fingerprint (hashes .SHA256 ())).decode ('UTF-8' )
160167
161168def process_certificate (payload ):
162- client = boto3client ('iot' )
169+ iot_client = boto3client ('iot' )
163170
164171 certificateText = base64 .b64decode (eval (payload ))
165172
@@ -197,6 +204,7 @@ def process_certificate(payload):
197204 return None
198205
199206def process_thing_group (thingGroupName , thingName ):
207+ iot_client = boto3client ('iot' )
200208 try :
201209 thingGroupArn = get_thing_group (thingGroupName )
202210 thingArn = get_thing (thingName )
@@ -211,6 +219,7 @@ def process_thing_group(thingGroupName, thingName):
211219 return None
212220
213221def get_name_from_certificate (certificateId ):
222+ iot_client = boto3client ('iot' )
214223 response = iot_client .describe_certificate (certificateId = certificateId )
215224 certificateText = response ["certificateDescription" ].get ("certificatePem" )
216225 certificateObj = x509 .load_pem_x509_certificate (data = certificateText .encode ('ascii' ), backend = default_backend ())
0 commit comments