首先需要一个 ListThings 权限 AWS 的 IAM 帐号,需要获取 access_key 与 secret_key。
此处用 python 代码演示,需要有 boto3 的包引用
sudo pip3 install boto3
from boto3.session import Session
aws_key = "xxxxxxxx" # 你的 access_key
aws_secret = "xxxxxxxx" # 你的 secret_key
session = Session(aws_access_key_id=aws_key,
aws_secret_access_key=aws_secret,
region_name="us-east-1", # 根据自己的地区调整
# region_name="us-west-2"
)
client = session.client("iot")
print("-" * 40 + "things")
request_things = client.list_things()
for thing in request_things["things"]:
print(thing["thingName"])