本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
透過 AWS CloudFormation 建立 AWS IoT Greengrass 資源
AWS IoT Greengrass 已與 AWS CloudFormation 整合,這項服務可協助您建立 AWS 資源的模型和設定,以減少建立和管理資源和基礎設施的時間。您創建一個描述所有的模板AWS您想要的資源 (例如元件版本和部署),以及AWS CloudFormation為您佈建和配置這些資源。
當您使用 AWS CloudFormation 時,您可以重複使用您的範本,重複、一致的設定您的 AWS IoT Greengrass 資源。只需描述一次您的資源,即可在多個 AWS 帳戶 與區域內重複佈建相同資源。
AWS IoT Greengrass 和 AWS CloudFormation 範本
若要佈建和配置 AWS IoT Greengrass 與相關服務的資源,您必須了解 AWS CloudFormation 範本。範本是以 JSON 或 YAML 格式化的文本檔案。而您亦可以透過這些範本的說明,了解欲在 AWS CloudFormation 堆疊中佈建的資源。如果您不熟悉 JSON 或 YAML,您可以使用 AWS CloudFormation Designer 協助您開始使用 AWS CloudFormation 範本。如需詳細資訊,請參閱 AWS CloudFormation 使用者指南中的什麼是 AWS CloudFormation Designer?。
AWS IoT Greengrass支援在中建立元件版本和部署AWS CloudFormation。如需詳細資訊 (包括元件版本和部署的 JSON 和 YAML 範本範例),請參閱AWS IoT Greengrass資源類型參考在AWS CloudFormation使用者指南。
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
進一步了解 AWS CloudFormation
若要進一步了解 AWS CloudFormation,請參閱下列資源: