Skip to content

Commit 7b4e587

Browse files
committed
Update iot_hello.py
1 parent 66065e6 commit 7b4e587

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

python/example_code/iot/iot_hello.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55
Purpose
66
7-
Shows how to get started with AWS IoT by describing the IoT endpoint.
7+
Shows how to get started with AWS IoT by listing up to 10 things.
88
"""
99

1010
import boto3
@@ -14,16 +14,22 @@
1414
# snippet-start:[python.example_code.iot.Hello]
1515
def hello_iot():
1616
"""
17-
Use the AWS SDK for Python (Boto3) to create an AWS IoT client and describe
18-
the IoT endpoint for your account.
17+
Use the AWS SDK for Python (Boto3) to create an AWS IoT client and list
18+
up to 10 things in your AWS IoT account.
1919
This example uses the default settings specified in your shared credentials
2020
and config files.
2121
"""
2222
try:
2323
iot_client = boto3.client("iot")
24-
response = iot_client.describe_endpoint(endpointType="iot:Data-ATS")
25-
endpoint = response["endpointAddress"]
26-
print(f"Hello, AWS IoT! Your endpoint is: {endpoint}")
24+
response = iot_client.list_things(maxResults=10)
25+
things = response.get("things", [])
26+
27+
print("Hello, AWS IoT! Here are your things:")
28+
if things:
29+
for i, thing in enumerate(things, 1):
30+
print(f"{i}. {thing['thingName']}")
31+
else:
32+
print("No things found in your AWS IoT account.")
2733
except ClientError as e:
2834
if e.response["Error"]["Code"] == "UnauthorizedException":
2935
print("You don't have permission to access AWS IoT.")

0 commit comments

Comments
 (0)