Deploy Lambda functions

Creating a Lambda function

  1. Select and click Lambda from the management console
  2. Click Create Function

Chap5

  1. Leave Author from scratch checked
  2. Enter GGv2workshop_alert_function in the function name (If multiple people are using a common environment, it is necessary to avoid collision of function names.You can use any name you like, so replace the function name in the following steps. Proceed, please)
  3. Select Python 3.8 for runtime

Chap5

  1. Click Create Function Action -> Upload .zip file Select

Chap5

  1. Select and upload the zip file saved in the local environment in the previous step
  2. Select Publish new version from Action and click Publish

Chap5

Creating and deploying components

  1. Click IoT Core from the management console
  2. Open the left menu Greengrass-> Component and click Create Component

Chap5

  1. Check Import Lambda function in Component Source
  2. Select the function GGv2workshop_alert_function created earlier as the Lambda function
  3. Select 1 (or latest version you have in lambda console) for version
  4. Enter my/topic in event source
  5. Click Create Component

Chap5

  1. The screen of the created component will be displayed, so click Deploy in the upper right.

Chap5

  1. From Add to existing Deployment, check the deployment destination is your Greengrass group you deployed earlier and click Next

Chap5

  1. Click Next as it is on the target specification screen
  2. Click Next on the component selection screen.
  3. Click Next as it is on the setting screen of the component
  4. Click Next as it is on the configuration screen for advanced settings
  5. Click Deploy on the review screen

With the above procedure, the deployment of the created lambda function is completed.

Operation check

  1. Click IoT Core from the management console
  2. Click test
  3. Enter # for the topic subscription and click subscribe to the topic

Chap5

The # we are doing this time is a multi-level wildcard that matches topics in multiple layers and subscribes to all messages received by IoT Core.

  1. Success if a message arrives at my/topic/alert

Chap5

In this hands-on, the local publisher outputs a value that follows a normal distribution with a mean value of 25 and a variance of 1 as dummy sensor data every second. The Lambda function created in this procedure sends a message to the IoT Core when the received value is greater than or equal to the threshold value of 25. Therefore, you need to wait for a while until you receive the message.