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!

asked 2 years ago333 views
1 Answer
1
Accepted Answer

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
EXPERT
answered 2 years ago
  • 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.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions