iot client register_certificate missing resourceArn and resourceId in ResourceAlreadyExistsException
See original GitHub issueI’m working on a registration script. When I register a certificate, which is already registered I get back ResourceAlreadyExistsException.
import boto3
import botocore
from collections import namedtuple
#debug
boto3.set_stream_logger(name='botocore')
CAResponse = namedtuple("CAResponse", "certId arn")
client = boto3.client('iot')
try:
with open("device_pem", 'r') as device_pem_file, open("rootCA.pem", 'r') as root_pem_file:
device_pem_string = device_pem_file.read()
root_pem_string = root_pem_file.read()
try:
response = self.client.register_certificate(
certificatePem=device_pem_string,
caCertificatePem=root_pem_string
)
if "certificateId" in response and "certificateArn" in response:
return CAResponse(certId=response["certificateId"], arn=response["certificateArn"])
except botocore.exceptions.ClientError as e:
print "%s register errror %r " % (e, e.response)
raise e
except IOError as e:
raise e
The exception is a botocore.errorfactory.ResourceAlreadyExistsException which I can’t seem to find the BotoCore source. When I cast it as a botocore.exceptions.ClientError I only get a Message & Code in the error.response.
With the logger running I can see that AWS gives the following response:
2017-02-13 17:03:52,634 botocore.parsers [DEBUG] Response body:
{
"message":"The certificate is already provisioned or registered",
"resourceArn":"target_arn",
"resourceId":"target_id"
}
Is there any way to retrieve this response body, or parse it out of the exception? As I see it there’s no function to retrieve the resourceArn & rescueId only by going through all of them wich will be a hassle when working with thousands of devices.
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
RegisterCertificate - AWS IoT
Registers a device certificate with AWS IoT in the same certificate mode as the signing CA. If you have more than one CA...
Read more >class IoT. Client - Boto3 Docs 1.26.33 documentation - AWS
A low-level client representing AWS IoT ... import boto3 client = boto3.client('iot') ... ResourceAlreadyExistsException; IoT.Client.exceptions.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi! you have to catch it from the client itself. eg from a cloudwatch logs client:
It seems this exception class gets created on the fly, so I don’t think it’s possible to import it. Has anybody found a way to catch it? I can import and catch
botocore.errorfactory.BaseClientExceptions
; is there a function to test whether it’s aResourceAlreadyExistsException
?