File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44"""
55Purpose
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
1010import boto3
1414# snippet-start:[python.example_code.iot.Hello]
1515def 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." )
You can’t perform that action at this time.
0 commit comments