本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用创建 Amazon IoT Greengrass 资源 Amazon CloudFormation
Amazon IoT Greengrass 与一项服务集成 Amazon CloudFormation,该服务可帮助您对 Amazon 资源进行建模和设置,从而减少创建和管理资源和基础架构所花费的时间。您可以创建一个描述所需的所有 Amazon 资源(例如组件版本和部署)的模板,并为您 Amazon CloudFormation 预置和配置这些资源。
使用时 Amazon CloudFormation,您可以重复使用模板来一致且重复地设置 Amazon IoT Greengrass 资源。只需描述一次您的资源,然后在多个 Amazon Web Services 账户 区域中一遍又一遍地配置相同的资源。
Amazon IoT Greengrass 和 Amazon CloudFormation 模板
要为和相关服务配置 Amazon IoT Greengrass 和配置资源,必须了解Amazon CloudFormation 模板。模板是 JSON 或 YAML 格式的文本文件。这些模板描述了您要在 Amazon CloudFormation 堆栈中配置的资源。如果你不熟悉 JSON 或 YAML,可以使用 D Amazon CloudFormation esigner 来帮助你开始使用 Amazon CloudFormation 模板。有关更多信息,请参阅《Amazon CloudFormation 用户指南》中的什么是 Amazon CloudFormation Designer?。
Amazon IoT Greengrass 支持在中创建组件版本和部署 Amazon CloudFormation。有关更多信息(包括组件版本和部署的 JSON 和 YAML 模板示例),请参阅《Amazon CloudFormation 用户指南》中的 Amazon IoT Greengrass 资源类型参考。
ComponentVersion 模板示例
以下是一个简单组件版本的 YAML 模板。为便于阅读,JSON 配方包含换行符。
Parameters:
ComponentVersion:
Type: String
Resources:
TestSimpleComponentVersion:
Type: AWS::GreengrassV2::ComponentVersion
Properties:
InlineRecipe: !Sub
- "{\n
\"RecipeFormatVersion\": \"2020-01-25\",\n
\"ComponentName\": \"component1\",\n
\"ComponentVersion\": \"${ComponentVersion}\",\n
\"ComponentType\": \"aws.greengrass.generic\",\n
\"ComponentDescription\": \"This\",\n
\"ComponentPublisher\": \"You\",\n
\"Manifests\": [\n
{\n
\"Platform\": {\n
\"os\": \"darwin\"\n
},\n
\"Lifecycle\": {},\n
\"Artifacts\": []\n
},\n
{\n
\"Lifecycle\": {},\n
\"Artifacts\": []\n
}\n
],\n
\"Lifecycle\": {\n
\"install\": {\n
\"script\": \"yuminstallpython\"\n
}\n
}\n
}"
- { ComponentVersion: !Ref ComponentVersion }
部署模板示例
以下是一个 YAML 文件,它定义了一个简单的部署模板。
Parameters:
ComponentVersion:
Type: String
TargetArn:
Type: String
Resources:
TestDeployment:
Type: AWS::GreengrassV2::Deployment
Properties:
Components:
component1:
ComponentVersion: !Ref ComponentVersion
TargetArn: !Ref TargetArn
DeploymentName: CloudFormationIntegrationTest
DeploymentPolicies:
FailureHandlingPolicy: DO_NOTHING
ComponentUpdatePolicy:
TimeoutInSeconds: 5000
Action: SKIP_NOTIFY_COMPONENTS
ConfigurationValidationPolicy:
TimeoutInSeconds: 30000
Outputs:
TestDeploymentArn:
Value: !Sub
- arn:${AWS::Partition}:greengrass:${AWS::Region}:${AWS::AccountId}:deployments:${DeploymentId}
- DeploymentId: !GetAtt TestDeployment.DeploymentId
了解更多关于 Amazon CloudFormation
要了解更多信息 Amazon CloudFormation,请参阅以下资源: