Greengrass Lambda with Compressed Binary Payload

0

I'm trying to configure a Greengrass Lambda to accept a binary encoding with the goal of sending a compressed JSON payload. My Lambda configuration looks something like:

  "componentLambdaParameters": {
    "inputPayloadEncodingType": "binary",
    "eventSources": [
      {
        "topic": "my/topic",
        "type": "IOT_CORE"
      }
    ],
    "linuxProcessParams": {
      "isolationMode": "NoContainer"
    },
    "pinned": false
  }

I'm using Python/Boto3 to send the messages, and the topic publish looks something like:

client = boto3.client("iot-data")
payload = gzip.compress(json.dumps({"large": "message"}).encode())
client.publish(topic="my/topic", qos=1, retain=True, payload=payload)

I get the following error from the Greengrass Lambda:

lambda_runtime.py:183,Cannot parse given invoke payload as JSON: b'my contents'

I can send the same message without compressing it (e.g. payload = json.dumps({"large": "message"}).encode()), and the Lambda succeeds. That suggests to me that "inputPayloadEncodingType": "binary" setting only works if the payload is encoded JSON, but that seems to defeat the purpose of using the binary payload option to send something other than JSON.

I'm using the Python 3.8 Lambda runtime with following component versions:

  "aws.greengrass.LambdaLauncher": {
    "componentVersion": "2.0.10"
  },
  "aws.greengrass.LambdaManager": {
    "componentVersion": "2.2.2"
  },
  "aws.greengrass.LambdaRuntimes": {
    "componentVersion": "2.0.8"
  },
  "aws.greengrass.Nucleus": {
    "componentVersion": "2.5.5",
  },

Is there something I might be doing wrong here or any other guidance on accepting a compressed payload? Thanks!

질문됨 2년 전340회 조회
1개 답변
1
수락된 답변

Hi,

When you deploy your lambda, make sure that you use "reset": [""] in the configuration update so that Greengrass will use the new default values. I suspect that you deployed the lambda in JSON mode and then changed it to binary without performing a reset. This means that Greengrass will continue to use the old configuration as the configuration will only change when you use reset/merge.

See: https://docs.aws.amazon.com/greengrass/v2/developerguide/update-component-configurations.html#reset-configuration-update

AWS
전문가
답변함 2년 전
  • Ahh, exactly right! Thanks so much, works now! I think that also explains some other confusions I had. My previous faulty understanding was that the configuration reset/merge features were used to modify the configuration of the same component version. In this case I deployed a new component version with the switch of the payload encoding type, so I didn't expect the configuration of the previous component version to persist.

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

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

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

관련 콘텐츠