通过使用 Amazon CLI创建自定义任务模板 - Amazon IoT Core
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

通过使用 Amazon CLI创建自定义任务模板

本主题介绍如何使用 Amazon CLI创建、删除任务模板以及检索有关详细信息。

从头开始创建任务模板

以下 Amazon CLI 命令显示如何使用作业文档创建作业 (job-document.json) 存储在 S3 存储桶中,角色有权从 Amazon S3 下载文件 (S3DownloadRole).

aws iot create-job-template \ --job-template-id 010 \ --document-source https://s3.amazonaws.com/amzn-s3-demo-bucket/job-document.json \ --timeout-config inProgressTimeoutInMinutes=100 \ --job-executions-rollout-config "{ \"exponentialRate\": { \"baseRatePerMinute\": 50, \"incrementFactor\": 2, \"rateIncreaseCriteria\": { \"numberOfNotifiedThings\": 1000, \"numberOfSucceededThings\": 1000}}, \"maximumPerMinute\": 1000}" \ --abort-config "{ \"criteriaList\": [ { \"action\": \"CANCEL\", \"failureType\": \"FAILED\", \"minNumberOfExecutedThings\": 100, \"thresholdPercentage\": 20}, { \"action\": \"CANCEL\", \"failureType\": \"TIMED_OUT\", \"minNumberOfExecutedThings\": 200, \"thresholdPercentage\": 50}]}" \ --presigned-url-config "{\"roleArn\":\"arn:aws:iam::123456789012:role/S3DownloadRole\", \"expiresInSec\":3600}"

可选的 timeout-config 参数指定每个设备完成任务运行所具有的时间。计时器在任务执行状态设置为 IN_PROGRESS 时启动。如果任务执行状态未在时间到期之前设置为其它最终状态,则会设置为 TIMED_OUT

进行中的计时器无法更新,将应用到该任务的所有任务启动。每当任务启动保持IN_PROGRESS状态的时间超过此时间间隔时,任务启动就会失败并切换到终端TIMED_OUT状态。 Amazon IoT 还会发布MQTT通知。

有关创建任务推出和中止相关配置的更多信息,请参阅任务推出和中止配置

注意

在您创建任务时,系统会检索指定为 Amazon S3 文件的任务文档。如果在创建任务后更改任务文档源 Amazon S3文件的内容,发送到任务目标的内容不会更改。

从现有任务创建任务模板

以下 Amazon CLI 命令通过指定现有任务的 Amazon 资源名称 (ARN) 来创建任务模板。新任务模板将使用任务中指定的所有配置。或者,您可以使用任何可选参数更改现有任务中的任何配置。

aws iot create-job-template \ --job-arn arn:aws:iot:region:123456789012:job/job-name \ --timeout-config inProgressTimeoutInMinutes=100

获取有关任务模板的详细信息

以下 Amazon CLI 命令获取有关指定作业模板的详细信息。

aws iot describe-job-template \ --job-template-id template-id

该命令将显示以下输出。

{ "abortConfig": { "criteriaList": [ { "action": "string", "failureType": "string", "minNumberOfExecutedThings": number, "thresholdPercentage": number } ] }, "createdAt": number, "description": "string", "document": "string", "documentSource": "string", "jobExecutionsRolloutConfig": { "exponentialRate": { "baseRatePerMinute": number, "incrementFactor": number, "rateIncreaseCriteria": { "numberOfNotifiedThings": number, "numberOfSucceededThings": number } }, "maximumPerMinute": number }, "jobTemplateArn": "string", "jobTemplateId": "string", "presignedUrlConfig": { "expiresInSec": number, "roleArn": "string" }, "timeoutConfig": { "inProgressTimeoutInMinutes": number } }

列出任务模板

以下 Amazon CLI 命令列出了您的所有作业模板 Amazon Web Services 账户。

aws iot list-job-templates

该命令将显示以下输出。

{ "jobTemplates": [ { "createdAt": number, "description": "string", "jobTemplateArn": "string", "jobTemplateId": "string" } ], "nextToken": "string" }

要检索其它结果页面,使用 nextToken 字段的值。

删除任务模板

以下 Amazon CLI 命令删除指定的作业模板。

aws iot delete-job-template \ --job-template-id template-id

该命令不显示任何输出。

从自定义任务模板创建任务。

以下 Amazon CLI 命令根据自定义作业模板创建作业。它以名为的设备为目标,thingOne并指定任务模板的 Amazon 资源名称 (ARN) 作为任务的基础。您可以覆盖高级配置(如超时和取消配置),方法是传递 create-job 命令的关联参数。

警告

仅当从 Amazon 托管式模板创建任务时,document-parameters 对象才能与 create-job 命令一起使用。此对象不得与自定义任务模板一起使用。有关演示如何使用此参数创建任务的示例,请参阅使用托管模板创建任务

aws iot create-job \ --targets arn:aws:iot:region:123456789012:thing/thingOne \ --job-template-arn arn:aws:iot:region:123456789012:jobtemplate/template-id