スキップしてコンテンツを表示

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"
    }
  }
}
2回答
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.

AWS
エキスパート
回答済み 3年前
AWS
エキスパート
レビュー済み 3年前
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.

回答済み 3年前
  • 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

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

関連するコンテンツ