AWS IoT Aanalytics的数据获取 [英] Data acquisition of AWS IoT Aanalytics
问题描述
我想通过指定Lambda的IoT Analytics数据集来获取最新数据.
I would like to obtain the latest data by specifying Lambda's IoT Analytics dataset.
如果使用aws sdk的IoTAnalytics的getDatasetContent,将仅返回用于下载文件的链接.数据本身无法获取.
If you use getDatasetContent of IoTAnalytics of aws sdk, only the link for downloading the file will be returned. Data itself can not be acquired.
我想知道如何从Lambda获取有关IoT Analytics数据集的信息.
I would like to know how to obtain information on the IoT Analytics data set from Lambda.
推荐答案
欢迎来到Stack Overflow!
Hi and welcome to Stack Overflow!
如果我正确理解了您的问题,那么您在问如何使用Lambda函数从IoT Analytics数据集中获取数据?
If I understand your question correctly, you are asking how to get the data from an IoT Analytics Dataset using a Lambda function?
您是正确的,get_dataset_content仅返回URI,但是随后很容易获取实际内容,例如在Python中看起来像这样;
You are correct that get_dataset_content only returns the URI, but it is simple to then fetch the actual content, for example in Python it would look like this;
# Code Fragment to retrieve content from IoT Analytics Dataset
iota = boto3.client('iotanalytics')
response = iota.get_dataset_content(datasetName='my_data_set',versionId='$LATEST')
contentState = response['status']['state']
if (contentState == 'SUCCEEDED') :
url = response['entries'][0]['dataURI']
stream = urllib.request.urlopen(url)
reader = csv.DictReader(codecs.iterdecode(stream, 'utf-8'))
for record in reader:
# Process the record as desired, you can refer to columns in the CSV
# by using record['column_name'] using the DictReader iterator
请注意,这段代码专门使用$ LATEST版本查看最新结果-您也可以查找$ LATEST_SUCCEEDED版本.
Note that this code is specifically looking at the most recent results using the $LATEST version - you can also look for the $LATEST_SUCCEEDED version.
还有更多此处的文档对于Boto-AWS Python SDK,但是您可以在所有其他sdk支持的语言中使用相同的方法.
There's more documentation here for Boto - the AWS Python SDK, but you can use the same approach in all other sdk supported languages.
希望有帮助,罗杰
这篇关于AWS IoT Aanalytics的数据获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!