AWS code-library documentation change
Summary
Added Python SDK (Boto3) introductory example listing IoT things with authentication error handling
Security assessment
The change adds a basic 'Hello World' example for listing IoT resources without modifying security configurations. While it includes authentication error handling, this is standard API usage documentation not related to security vulnerabilities or security feature implementation.
Diff
diff --git a/code-library/latest/ug/iot_example_iot_Hello_section.md b/code-library/latest/ug/iot_example_iot_Hello_section.md index c7d7d6580..707909457 100644 --- a//code-library/latest/ug/iot_example_iot_Hello_section.md +++ b//code-library/latest/ug/iot_example_iot_Hello_section.md @@ -331,0 +332,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_. + + + +