내용으로 건너뛰기

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

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

관련 콘텐츠