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.

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则