0

我有一个使用 boto3 创建 IoT Analytics 路径的 python 程序。我的程序能够成功创建通道和数据存储,但是当我尝试通过创建管道功能连接两者时失败。我的代码如下:

dactivity =  [{ 
          "channel": { 
          "channelName": channel["channelName"],
          "name": IoTAConfig["channelName"],
          "next" : IoTAConfig["datastoreName"]
           },
          "datastore": { 
          "datastoreName": ds["datastoreName"],
          "name": IoTAConfig["datastoreName"]
          }
          }]
pipeline = iota.create_pipeline(
        pipelineActivities = dactivity,           
        pipelineName = IoTAConfig["pipelineName"]
    )

错误代码如下:

Traceback (most recent call last):
  File "createFullGG.py", line 478, in <module>
    createIoTA()
  File "createFullGG.py", line 268, in createIoTA
    pipelineName = IoTAConfig["pipelineName"]
  File "/usr/lib/python2.7/site-packages/botocore/client.py", line 320, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/lib/python2.7/site-packages/botocore/client.py", line 623, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.errorfactory.InvalidRequestException: An error occurred (InvalidRequestException) when calling the UpdatePipeline operation: PipelineActivity must have one and only one member

根据文档,管道活动可以包含 1 到 25 个条目,只要它们位于 1 个对象的数组中。我不知道为什么这继续失败。任何帮助表示赞赏。

4

1 回答 1

0

由于可选元素的表示方式,公共文档看起来有点混乱,好消息是这很容易解决。

您正在尝试的更正版本将被写为;

dactivity=[
    {
          "channel": {
                "channelName": channel["channelName"],
                "name": IoTAConfig["channelName"],
                "next" : IoTAConfig["datastoreName"]
           }
    },
    {
          "datastore": {
                "datastoreName": ds["datastoreName"],
                "name": IoTAConfig["datastoreName"]
          }
    }
]

response = client.create_pipeline(
        pipelineActivities = dactivity,
        pipelineName = IoTAConfig["pipelineName"] 
    )

因此,这是您提供的一系列活动,例如 [ {A1},{A2} ] 是否有意义?

这有帮助吗?

于 2018-11-07T21:54:59.417 回答