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"
    }
  }
}
posta 2 anni fa317 visualizzazioni
2 Risposte
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
ESPERTO
Jan_B
con risposta 2 anni fa
profile pictureAWS
ESPERTO
Greg_B
verificato 2 anni fa
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.

con risposta 2 anni fa
  • 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

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande