Amazon CloudFormation 支持 Amazon IoT Greengrass - Amazon IoT Greengrass
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

Amazon IoT Greengrass Version 1在 2023 年 6 月 30 日之前,不再接收功能更新,只会收到安全补丁和错误修复。有关更多信息,请参阅 。Amazon IoT Greengrass V1维护政策. 强烈建议您迁移到Amazon IoT Greengrass Version 2,它补充说重要新功能对其他平台的支持.

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

Amazon CloudFormation 支持 Amazon IoT Greengrass

Amazon CloudFormation 是一项服务,可帮助您创建、管理和复制您的 Amazon 资源。您可以使用Amazon CloudFormation要定义的模板Amazon IoT Greengrass组和要部署的客户端设备、订阅及其他组件。有关示例,请参阅示例 模板

您从模板中生成的资源和基础设施称为堆栈。您可以在一个模板中定义所有资源,也可以引用其他堆栈中的资源。有关 的更多信息Amazon CloudFormation模板和功能,请参阅是什么Amazon CloudFormation?中的Amazon CloudFormation用户指南.

创建资源

Amazon CloudFormation 模板是描述 Amazon 资源的属性和关系的 JSON 或 YAML 文档。支持以下 Amazon IoT Greengrass 资源:

  • 核心

  • 客户端设备(设备)

  • Lambda 函数

  • 连接器

  • 资源(本地、机器学习和密钥)

  • 订阅

  • 日志记录程序(日志记录配置)

在 Amazon CloudFormation 模板中,Greengrass 资源的结构和语法基于 Amazon IoT Greengrass API。例如,示例模板关联顶级用户DeviceDefinition有一个DeviceDefinitionVersion包含单个客户端设备。有关更多信息,请参阅 Amazon IoT Greengrass 组对象模型概述

这些区域有:Amazon IoT Greengrass资源类型参考中的Amazon CloudFormation用户指南描述了可以用来管理的 Greengrass 资源Amazon CloudFormation. 当您使用 Amazon CloudFormation 模板创建 Greengrass 资源时,我们建议您仅从 Amazon CloudFormation 管理这些资源。例如,如果您要添加、更改或删除设备,则应更新您的模板(而不是使用Amazon IoT GreengrassAPI 或Amazon IoT控制台)。这允许您使用回滚及其他 Amazon CloudFormation 更改管理功能。有关使用的更多信息Amazon CloudFormation要创建和管理您的资源和堆栈,请参阅。使用堆栈中的Amazon CloudFormation用户指南.

有关说明如何创建和部署的演练Amazon IoT Greengrass资源在Amazon CloudFormation模板,请参阅使用 实现自动化Amazon IoT Greengrass设置Amazon CloudFormation上的 IoT onAmazon官方博客。

部署资源

在创建一个Amazon CloudFormation包含组版本的堆栈,您可以使用Amazon CLI要么Amazon IoT控制台来部署它。

注意

要部署组,您必须具有与您的关联的 Greengrass 服务角色Amazon Web Services 账户. 服务角色允许Amazon IoT Greengrass在中访问您的资源Amazon Lambda和OtherAmazon服务。如果您已在当前 Greengrass 组中部署了 Greengrass 组,则该角色应存在Amazon Web Services 区域. 有关更多信息,请参阅 Greengrass 服务角色

部署组 (Amazon CLI)
  • 运行 create-deployment 命令。

    aws greengrass create-deployment --group-id GroupId --group-version-id GroupVersionId --deployment-type NewDeployment
    注意

    这些区域有:CommandToDeployGroup中的语句示例模板演示了在创建堆栈时如何使用组和组版本 ID 输出命令。

部署组(控制台)
  1. 在Amazon IoT控制台导航窗格,在Manage,展开Greengrass,然后选择组 (V1).

  2. 选择您的组。

  3. 在组配置页面上,选择部署.

示例 模板

以下示例模板创建一个包含核心、客户端设备、日志记录程序、日志记录程序、日志记录程序、日志记录程序、和两种资源的 Greengrass 组。为此,该模板采用 Amazon IoT Greengrass API 的对象模型。例如,要添加到组的客户端设备包含在DeviceDefinitionVersion资源,它与DeviceDefinition资源。要将设备添加到组,组版本将引用 DeviceDefinitionVersion 的 ARN。

该模板包含的参数可让您指定核心和设备的证书 ARN 以及源 Lambda 函数(这是一个Amazon Lambda资源)。该模板使用 RefGetAtt 内部函数引用创建 Greengrass 资源所需的 ID、ARN 和其他属性。

该模板还定义了两个Amazon IoT设备(事物),这表示要添加到 Greengrass 组的核心和客户端设备。

在使用您的 Greengrass 资源创建堆栈后,您可以使用Amazon CLI或者Amazon IoT控制台到部署组.

注意

该示例中的 CommandToDeployGroup 语句说明如何输出可用于部署组的完整 create-deployment CLI 命令。

JSON
{ "AWSTemplateFormatVersion": "2010-09-09", "Description": "AWS IoT Greengrass example template that creates a group version with a core, device, function, logger, subscription, and resources.", "Parameters": { "CoreCertificateArn": { "Type": "String" }, "DeviceCertificateArn": { "Type": "String" }, "LambdaVersionArn": { "Type": "String" } }, "Resources": { "TestCore1": { "Type": "AWS::IoT::Thing", "Properties": { "ThingName": "TestCore1" } }, "TestCoreDefinition": { "Type": "AWS::Greengrass::CoreDefinition", "Properties": { "Name": "DemoTestCoreDefinition" } }, "TestCoreDefinitionVersion": { "Type": "AWS::Greengrass::CoreDefinitionVersion", "Properties": { "CoreDefinitionId": { "Ref": "TestCoreDefinition" }, "Cores": [ { "Id": "TestCore1", "CertificateArn": { "Ref": "CoreCertificateArn" }, "SyncShadow": "false", "ThingArn": { "Fn::Join": [ ":", [ "arn:aws:iot", { "Ref": "AWS::Region" }, { "Ref": "AWS::AccountId" }, "thing/TestCore1" ] ] } } ] } }, "TestClientDevice1": { "Type": "AWS::IoT::Thing", "Properties": { "ThingName": "TestClientDevice1" } }, "TestDeviceDefinition": { "Type": "AWS::Greengrass::DeviceDefinition", "Properties": { "Name": "DemoTestDeviceDefinition" } }, "TestDeviceDefinitionVersion": { "Type": "AWS::Greengrass::DeviceDefinitionVersion", "Properties": { "DeviceDefinitionId": { "Fn::GetAtt": [ "TestDeviceDefinition", "Id" ] }, "Devices": [ { "Id": "TestClientDevice1", "CertificateArn": { "Ref": "DeviceCertificateArn" }, "SyncShadow": "true", "ThingArn": { "Fn::Join": [ ":", [ "arn:aws:iot", { "Ref": "AWS::Region" }, { "Ref": "AWS::AccountId" }, "thing/TestClientDevice1" ] ] } } ] } }, "TestFunctionDefinition": { "Type": "AWS::Greengrass::FunctionDefinition", "Properties": { "Name": "DemoTestFunctionDefinition" } }, "TestFunctionDefinitionVersion": { "Type": "AWS::Greengrass::FunctionDefinitionVersion", "Properties": { "FunctionDefinitionId": { "Fn::GetAtt": [ "TestFunctionDefinition", "Id" ] }, "DefaultConfig": { "Execution": { "IsolationMode": "GreengrassContainer" } }, "Functions": [ { "Id": "TestLambda1", "FunctionArn": { "Ref": "LambdaVersionArn" }, "FunctionConfiguration": { "Pinned": "true", "Executable": "run.exe", "ExecArgs": "argument1", "MemorySize": "512", "Timeout": "2000", "EncodingType": "binary", "Environment": { "Variables": { "variable1": "value1" }, "ResourceAccessPolicies": [ { "ResourceId": "ResourceId1", "Permission": "ro" }, { "ResourceId": "ResourceId2", "Permission": "rw" } ], "AccessSysfs": "false", "Execution": { "IsolationMode": "GreengrassContainer", "RunAs": { "Uid": "1", "Gid": "10" } } } } } ] } }, "TestLoggerDefinition": { "Type": "AWS::Greengrass::LoggerDefinition", "Properties": { "Name": "DemoTestLoggerDefinition" } }, "TestLoggerDefinitionVersion": { "Type": "AWS::Greengrass::LoggerDefinitionVersion", "Properties": { "LoggerDefinitionId": { "Ref": "TestLoggerDefinition" }, "Loggers": [ { "Id": "TestLogger1", "Type": "AWSCloudWatch", "Component": "GreengrassSystem", "Level": "INFO" } ] } }, "TestResourceDefinition": { "Type": "AWS::Greengrass::ResourceDefinition", "Properties": { "Name": "DemoTestResourceDefinition" } }, "TestResourceDefinitionVersion": { "Type": "AWS::Greengrass::ResourceDefinitionVersion", "Properties": { "ResourceDefinitionId": { "Ref": "TestResourceDefinition" }, "Resources": [ { "Id": "ResourceId1", "Name": "LocalDeviceResource", "ResourceDataContainer": { "LocalDeviceResourceData": { "SourcePath": "/dev/TestSourcePath1", "GroupOwnerSetting": { "AutoAddGroupOwner": "false", "GroupOwner": "TestOwner" } } } }, { "Id": "ResourceId2", "Name": "LocalVolumeResourceData", "ResourceDataContainer": { "LocalVolumeResourceData": { "SourcePath": "/dev/TestSourcePath2", "DestinationPath": "/volumes/TestDestinationPath2", "GroupOwnerSetting": { "AutoAddGroupOwner": "false", "GroupOwner": "TestOwner" } } } } ] } }, "TestSubscriptionDefinition": { "Type": "AWS::Greengrass::SubscriptionDefinition", "Properties": { "Name": "DemoTestSubscriptionDefinition" } }, "TestSubscriptionDefinitionVersion": { "Type": "AWS::Greengrass::SubscriptionDefinitionVersion", "Properties": { "SubscriptionDefinitionId": { "Ref": "TestSubscriptionDefinition" }, "Subscriptions": [ { "Id": "TestSubscription1", "Source": { "Fn::Join": [ ":", [ "arn:aws:iot", { "Ref": "AWS::Region" }, { "Ref": "AWS::AccountId" }, "thing/TestClientDevice1" ] ] }, "Subject": "TestSubjectUpdated", "Target": { "Ref": "LambdaVersionArn" } } ] } }, "TestGroup": { "Type": "AWS::Greengrass::Group", "Properties": { "Name": "DemoTestGroupNewName", "RoleArn": { "Fn::Join": [ ":", [ "arn:aws:iam:", { "Ref": "AWS::AccountId" }, "role/TestUser" ] ] }, "InitialVersion": { "CoreDefinitionVersionArn": { "Ref": "TestCoreDefinitionVersion" }, "DeviceDefinitionVersionArn": { "Ref": "TestDeviceDefinitionVersion" }, "FunctionDefinitionVersionArn": { "Ref": "TestFunctionDefinitionVersion" }, "SubscriptionDefinitionVersionArn": { "Ref": "TestSubscriptionDefinitionVersion" }, "LoggerDefinitionVersionArn": { "Ref": "TestLoggerDefinitionVersion" }, "ResourceDefinitionVersionArn": { "Ref": "TestResourceDefinitionVersion" } }, "Tags": { "KeyName0": "value", "KeyName1": "value", "KeyName2": "value" } } } }, "Outputs": { "CommandToDeployGroup": { "Value": { "Fn::Join": [ " ", [ "groupVersion=$(cut -d'/' -f6 <<<", { "Fn::GetAtt": [ "TestGroup", "LatestVersionArn" ] }, ");", "aws --region", { "Ref": "AWS::Region" }, "greengrass create-deployment --group-id", { "Ref": "TestGroup" }, "--deployment-type NewDeployment --group-version-id", "$groupVersion" ] ] } } } }
YAML
AWSTemplateFormatVersion: 2010-09-09 Description: >- AWS IoT Greengrass example template that creates a group version with a core, device, function, logger, subscription, and resources. Parameters: CoreCertificateArn: Type: String DeviceCertificateArn: Type: String LambdaVersionArn: Type: String Resources: TestCore1: Type: 'AWS::IoT::Thing' Properties: ThingName: TestCore1 TestCoreDefinition: Type: 'AWS::Greengrass::CoreDefinition' Properties: Name: DemoTestCoreDefinition TestCoreDefinitionVersion: Type: 'AWS::Greengrass::CoreDefinitionVersion' Properties: CoreDefinitionId: !Ref TestCoreDefinition Cores: - Id: TestCore1 CertificateArn: !Ref CoreCertificateArn SyncShadow: 'false' ThingArn: !Join - ':' - - 'arn:aws:iot' - !Ref 'AWS::Region' - !Ref 'AWS::AccountId' - thing/TestCore1 TestClientDevice1: Type: 'AWS::IoT::Thing' Properties: ThingName: TestClientDevice1 TestDeviceDefinition: Type: 'AWS::Greengrass::DeviceDefinition' Properties: Name: DemoTestDeviceDefinition TestDeviceDefinitionVersion: Type: 'AWS::Greengrass::DeviceDefinitionVersion' Properties: DeviceDefinitionId: !GetAtt - TestDeviceDefinition - Id Devices: - Id: TestClientDevice1 CertificateArn: !Ref DeviceCertificateArn SyncShadow: 'true' ThingArn: !Join - ':' - - 'arn:aws:iot' - !Ref 'AWS::Region' - !Ref 'AWS::AccountId' - thing/TestClientDevice1 TestFunctionDefinition: Type: 'AWS::Greengrass::FunctionDefinition' Properties: Name: DemoTestFunctionDefinition TestFunctionDefinitionVersion: Type: 'AWS::Greengrass::FunctionDefinitionVersion' Properties: FunctionDefinitionId: !GetAtt - TestFunctionDefinition - Id DefaultConfig: Execution: IsolationMode: GreengrassContainer Functions: - Id: TestLambda1 FunctionArn: !Ref LambdaVersionArn FunctionConfiguration: Pinned: 'true' Executable: run.exe ExecArgs: argument1 MemorySize: '512' Timeout: '2000' EncodingType: binary Environment: Variables: variable1: value1 ResourceAccessPolicies: - ResourceId: ResourceId1 Permission: ro - ResourceId: ResourceId2 Permission: rw AccessSysfs: 'false' Execution: IsolationMode: GreengrassContainer RunAs: Uid: '1' Gid: '10' TestLoggerDefinition: Type: 'AWS::Greengrass::LoggerDefinition' Properties: Name: DemoTestLoggerDefinition TestLoggerDefinitionVersion: Type: 'AWS::Greengrass::LoggerDefinitionVersion' Properties: LoggerDefinitionId: !Ref TestLoggerDefinition Loggers: - Id: TestLogger1 Type: AWSCloudWatch Component: GreengrassSystem Level: INFO TestResourceDefinition: Type: 'AWS::Greengrass::ResourceDefinition' Properties: Name: DemoTestResourceDefinition TestResourceDefinitionVersion: Type: 'AWS::Greengrass::ResourceDefinitionVersion' Properties: ResourceDefinitionId: !Ref TestResourceDefinition Resources: - Id: ResourceId1 Name: LocalDeviceResource ResourceDataContainer: LocalDeviceResourceData: SourcePath: /dev/TestSourcePath1 GroupOwnerSetting: AutoAddGroupOwner: 'false' GroupOwner: TestOwner - Id: ResourceId2 Name: LocalVolumeResourceData ResourceDataContainer: LocalVolumeResourceData: SourcePath: /dev/TestSourcePath2 DestinationPath: /volumes/TestDestinationPath2 GroupOwnerSetting: AutoAddGroupOwner: 'false' GroupOwner: TestOwner TestSubscriptionDefinition: Type: 'AWS::Greengrass::SubscriptionDefinition' Properties: Name: DemoTestSubscriptionDefinition TestSubscriptionDefinitionVersion: Type: 'AWS::Greengrass::SubscriptionDefinitionVersion' Properties: SubscriptionDefinitionId: !Ref TestSubscriptionDefinition Subscriptions: - Id: TestSubscription1 Source: !Join - ':' - - 'arn:aws:iot' - !Ref 'AWS::Region' - !Ref 'AWS::AccountId' - thing/TestClientDevice1 Subject: TestSubjectUpdated Target: !Ref LambdaVersionArn TestGroup: Type: 'AWS::Greengrass::Group' Properties: Name: DemoTestGroupNewName RoleArn: !Join - ':' - - 'arn:aws:iam:' - !Ref 'AWS::AccountId' - role/TestUser InitialVersion: CoreDefinitionVersionArn: !Ref TestCoreDefinitionVersion DeviceDefinitionVersionArn: !Ref TestDeviceDefinitionVersion FunctionDefinitionVersionArn: !Ref TestFunctionDefinitionVersion SubscriptionDefinitionVersionArn: !Ref TestSubscriptionDefinitionVersion LoggerDefinitionVersionArn: !Ref TestLoggerDefinitionVersion ResourceDefinitionVersionArn: !Ref TestResourceDefinitionVersion Tags: KeyName0: value KeyName1: value KeyName2: value Outputs: CommandToDeployGroup: Value: !Join - ' ' - - groupVersion=$(cut -d'/' -f6 <<< - !GetAtt - TestGroup - LatestVersionArn - ); - aws --region - !Ref 'AWS::Region' - greengrass create-deployment --group-id - !Ref TestGroup - '--deployment-type NewDeployment --group-version-id' - $groupVersion

支持 Amazon Web Services 区域

目前,您可以创建和管理Amazon IoT Greengrass仅在以下资源中Amazon Web Services 区域s

  • 美国东部(俄亥俄)

  • 美国东部(弗吉尼亚北部)

  • 美国西部(俄勒冈)

  • Asia Pacific (Mumbai)

  • 亚太地区(首尔)

  • 亚太地区(新加坡)

  • 亚太地区(悉尼)

  • 亚太地区(东京)

  • 中国(北京)

  • 欧洲(法兰克福)

  • 欧洲(爱尔兰)

  • 欧洲(伦敦)

  • Amazon GovCloud (Us-West)