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.

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ