1.- 创建一个core device

创建1部EC2作为core device,过程如下

AWS Lab: Deploy IoT Greengrass Components_iot

AWS Lab: Deploy IoT Greengrass Components_aws_02

复制相关命令在EC2上跑即可,完成后检查:/greengrass/v2/bin/greengrass-cli -V

AWS Lab: Deploy IoT Greengrass Components_iot_03

2.- 创建component

components consist of two types of files:

--artifact, The artifact files contain the scripts, compiled code, or any other resources that the component requires.

--recipe, The recipe file contains the metadata and configuration information for the component, such as the platform it can run on, parameter settings, commands to install, run, or shut down the component, and the location of the artifact files.

默认文件已经放在:/home/ec2-user/greenhouse_components

/greenhouse_components/artifacts/com.greenhouse.VentilationControl/1.0.0/controller.py

/greenhouse_components/recipes/com.greenhouse.VentilationControl-1.0.0.json

3.- 本地直接deploy component

Before you deploy the ventilation control component into production, you would like to perform a local test to ensure it functions as you intend it to.

sudo /greengrass/v2/bin/greengrass-cli deployment create --recipeDir ~/greenhouse_components/recipes --artifactDir ~/greenhouse_components/artifacts --merge "com.greenhouse.VentilationControl=1.0.0"

AWS Lab: Deploy IoT Greengrass Components_aws_04

验证:tail /tmp/ventilation_control.log

AWS Lab: Deploy IoT Greengrass Components_component_05

查看已安装的所有component

sudo /greengrass/v2/bin/greengrass-cli component list

AWS Lab: Deploy IoT Greengrass Components_aws_06

If the component does not seem to deploy correctly, or you are not receiving similar results to the verification steps, run the following command to view the Greengrass log file:

sudo tail /greengrass/v2/logs/greengrass.log

4.- 通过AWS IoT部署component

将artifact文件上传到S3

AWS Lab: Deploy IoT Greengrass Components_iot_07

创建component

AWS Lab: Deploy IoT Greengrass Components_component_08

将receip的json文件内容copy进去

AWS Lab: Deploy IoT Greengrass Components_aws_09

注意更正artifact的S3路径

AWS Lab: Deploy IoT Greengrass Components_aws_10

AWS Lab: Deploy IoT Greengrass Components_aws_11

AWS Lab: Deploy IoT Greengrass Components_aws_12

5.- 创建Deployment

先删除之前在本地上部署的用于验证目的的component

sudo /greengrass/v2/bin/greengrass-cli deployment create --remove com.greenhouse.VentilationControl

AWS Lab: Deploy IoT Greengrass Components_aws_13

AWS Lab: Deploy IoT Greengrass Components_aws_14

AWS Lab: Deploy IoT Greengrass Components_iot_15

AWS Lab: Deploy IoT Greengrass Components_component_16

AWS Lab: Deploy IoT Greengrass Components_aws_17

后面按默认Next

完成后,稍等一会可以查看部署情况

AWS Lab: Deploy IoT Greengrass Components_component_18

在EC2上查看:sudo /greengrass/v2/bin/greengrass-cli component list

AWS Lab: Deploy IoT Greengrass Components_iot_19

AWS Lab: Deploy IoT Greengrass Components_component_20