AWS iot documentation change
Summary
Added Python SDK example code for listing AWS IoT things with error handling
Security assessment
The change adds error handling for credentials and permissions (UnauthorizedException/NoCredentialsError) which demonstrates security best practices, but does not address a specific security vulnerability. The documentation improvement shows proper credential handling patterns.
Diff
diff --git a/iot/latest/developerguide/example_iot_Hello_section.md b/iot/latest/developerguide/example_iot_Hello_section.md index 106462f9d..029517a5b 100644 --- a//iot/latest/developerguide/example_iot_Hello_section.md +++ b//iot/latest/developerguide/example_iot_Hello_section.md @@ -329,0 +330,48 @@ There's more on GitHub. Find the complete example and learn how to set up and ru +Python + + +**SDK for Python (Boto3)** + + +###### Note + +There's more on GitHub. Find the complete example and learn how to set up and run in the [AWS Code Examples Repository](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/python/example_code/iot#code-examples). + + + def hello_iot(): + """ + Use the AWS SDK for Python (Boto3) to create an AWS IoT client and list + up to 10 things in your AWS IoT account. + This example uses the default settings specified in your shared credentials + and config files. + """ + try: + iot_client = boto3.client("iot") + response = iot_client.list_things(maxResults=10) + things = response.get("things", []) + + print("Hello, AWS IoT! Here are your things:") + if things: + for i, thing in enumerate(things, 1): + print(f"{i}. {thing['thingName']}") + else: + print("No things found in your AWS IoT account.") + except ClientError as e: + if e.response["Error"]["Code"] == "UnauthorizedException": + print("You don't have permission to access AWS IoT.") + else: + print(f"Couldn't access AWS IoT. Error: {e}") + except NoCredentialsError: + print("No AWS credentials found. Please configure your credentials.") + except Exception as e: + print(f"An unexpected error occurred: {e}") + + + + + + * For API details, see [listThings](https://docs.aws.amazon.com/goto/boto3/iot-2015-05-28/listThings) in _AWS SDK for Python (Boto3) API Reference_. + + + +