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.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南