Migrating Lambda from Greengrass v1 to Greengrass v2

0

Hello, we're in the process of migrating a long running Lambda function from Greengrass v1 to v2.

So far it all works well and we eventually managed to get it to run in Greengrass v2 without exceptions.

With Greengrass v1 based on a subscription all changes made to the shadow led to calls to the Lambda handler with the JSON delta as a parameter. With Greengrass v2 we're not getting these calls anymore. I guess I could explicitly subscribe for the delta in my pinned Lambda function but that feels wrong as it would make the handler obsolete. Can you please help with the best approach to get to process the shadow deltas in Greengrass v2?

For the record, the ShadowManager configuration is

"aws.greengrass.ShadowManager": {
  "componentVersion": "2.3.5",
  "configurationUpdate": {
    "merge": "{\"synchronize\":{\"coreThing\":{}}}"
  }
}

and my understanding is that both direction = betweenDeviceAndCloud and coreThing.classic = true are defaults.

질문됨 4달 전334회 조회
1개 답변
1
수락된 답변

Hello,

How did you configure the Lambda's event source? You need to configure the lambda with an event source on the delta topic for shadow as shown here: https://docs.aws.amazon.com/greengrass/v2/developerguide/interact-with-shadows-in-components.html#react-shadow-events.

Cheers, Michael

AWS
전문가
답변함 4달 전
  • Thank you for pointing me in the right direction. For the record in my lambda config I've added

      "eventSources": [
        {
          "type": "PUB_SUB",
          "topic": "$aws/things/ThingName/shadow/update/delta"
        }
      ],
    

    and in the access control section of the deployment recipe I have

    "aws.greengrass.ipc.pubsub": {
      "ComponentName:pubsub:1": {
        "policyDescription": "Allows access to shadow pubsub topics",
        "operations": [
          "aws.greengrass#SubscribeToTopic"
        ],
        "resources": [
          "$aws/things/{iot:thingName}/shadow/get/accepted"
        ]
      }
    }
    

    The lambda handler does indeed get now called although I still have a little issue with parsing the input as I get Failed to parse input payload: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of java.lang.String out of START_OBJECT token.

    My handler is RequestHandler<String, Unit> (this is Kotlin, in Java it would be Void)

    May I ask what type the input is and please point me to some documentation for the conversion?

  • With an event source you do not need any access control to subscribe. Lambda will subscribe for you.

    If you set your lambda's inputPayloadEncodingType to JSON instead of BINARY then the input will be a map

  • Thank you very much for your help. It's much appreciated. I finally got it to work by setting inputPayloadEncodingType to binary and implementing RequestHandler<InputStream, Unit>.

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

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

질문 답변하기에 대한 가이드라인

관련 콘텐츠