Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Error handling in Blinky-Hello-World #105

Open
katoy opened this issue Aug 17, 2024 · 0 comments
Open

Change Error handling in Blinky-Hello-World #105

katoy opened this issue Aug 17, 2024 · 0 comments

Comments

@katoy
Copy link

katoy commented Aug 17, 2024

I found wrong code in Blinky-Hello-World/register_thing.py

$ git diff fix_error_handling -- register_thing.py 
diff --git a/Blinky-Hello-World/register_thing.py b/Blinky-Hello-World/register_thing.py
index a7d9fec..6f8ce13 100644
--- a/Blinky-Hello-World/register_thing.py
+++ b/Blinky-Hello-World/register_thing.py
@@ -142,12 +142,11 @@ def generate_signer_certificate():
     print("Generating self-signed x.509 certificate...")
     try:
         aws_iot_reg_code = iot.get_registration_code()
-    except ClientError as e:
-        print(str(e))
-        print(e.response['Error']['Code'])
+    except ClientError:
+        print(ClientError.response['Error']['Code'])
         print("Error with the AWS CLI when running the command 'aws iot get-registration-code'.")
-        exit(1)
-
+        exit(0)
+    
     signer_public_key = signer_key.public_key()
     time_now = datetime.utcnow()
     days_to_expire = 365

When I used the modified code, I encountered the following error:

An error occurred (AccessDeniedException) when calling the GetRegistrationCode operation: User: arn:aws:iam::xxxxxxxxxxxx:user/xxx-xxx is not authorized to perform: iot:GetRegistrationCode on resource: * because no identity-based policy allows the iot:GetRegistrationCode action
AccessDeniedException
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant