Greengrass Lambdas Running on Core Device - Using a Variable in the Topic

0

I want to create a generic greengrass component that runs a lambda function. I have data that is sent to a topic such as

plugin/config/"THINGNAME"

"THINGNAME" is the name of each individual thing. Is it possible to set the event source to the a topic which includes the variable for the thingName?

eg. plugin/config/{iot:thingName}

Each core device that runs this component will have a difference event source based on the thingName.

Below is an example of what I have set the default configuration to it does not work as intended.

It interprets the variable as a literal string.

 {
  "lambdaExecutionParameters": {
    "EnvironmentVariables": {}
  },
  "containerParams": {
    "memorySize": 16384,
    "mountROSysfs": false,
    "volumes": {},
    "devices": {}
  },
  "containerMode": "NoContainer",
  "timeoutInSeconds": 10,
  "maxInstancesCount": 100,
  "inputPayloadEncodingType": "json",
  "maxQueueSize": 1000,
  "pinned": true,
  "maxIdleTimeInSeconds": 60,
  "statusTimeoutInSeconds": 60,
  "pubsubTopics": {
    "0": {
      "topic": "plugin/config/{iot:thingName}",
      "type": "IOT_CORE"
    }
  }
}
asked 2 years ago286 views
2 Answers
1

Hi Phil, {iot:thingName} is a supported GGv2 recipe variables, but to use recipe variables in Component Configuration you need to set the Greengrass nucleus Configuration option interpolateComponentConfiguration to true as explained here

As an alternative to a GGv2 Lambda you can also use directly the Greengras IPC SDK (python, C++, Java ) in your component code to publish/subscribe to messages as described in the AWS IoT Greengrass documentation or here in the 5.2 Subscriber Implementation section of the AWS Greengrass V2 workshop.

profile pictureAWS
EXPERT
Jan_B
answered 2 years ago
profile pictureAWS
EXPERT
Greg_B
reviewed 2 years ago
0

Hi Jan,

Thanks for the quick response. I can confirm this now works after revising the deployment and setting the aws.greengras.Nucleus configuration to merge to:

{
	"interpolateComponentConfiguration": "true"
}

and redeploying my lambda component with

  "pubsubTopics": {
    "0": {
      "topic": "plugin/config/{iot:thingName}",
      "type": "IOT_CORE"
    }

Why is IPC preferred over lambda's? Lambdas have a a very easy interface to set up event sources and currently my lambda runtime is nodejs14.x and the javascript SDK doesn't support IPC.

answered 2 years ago
  • You have a perfect valid case for using Lambdas on GGv2. Lambda on GGv2 make sense :

    • for porting GGv1 Lambda functions to GGv2
    • you have stateless functions with no integration need with the GGv2 IPC API
    • or you use a programming language with no supported Greengrass SDK and need to trigger code on incoming messages

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions