IoT Events custom JSON payload not working

0

I'm trying to use IoT Events custom payload with Lambda action. When I pass a JSON list format data from input and use it in the Lambda Action with JSON payload the following error occurs:

We couldn't parse your content expression for the payload of LambdaAction. Enter a content expression with the correct syntax.

Code example:

{ lambda: { functionArn: consumer.functionArn, payload: { contentExpression: "{\"deviceId\": \"test\", \"applianceId\": \"another test\"}", type: 'JSON' } } }

The answer from https://repost.aws/questions/QUJ23sjtbVTMSmG4JzITEK1g/io-t-events-custom-payload-error not working. Did something change?

已提问 2 年前703 查看次数
2 回答
0

I used the kind of content expression you have provided in the question and I could get the desired response with Lambda action.

"{
    \"deviceId\": \"test\", 
    \"applianceId\": \"another test\"
}"

Event received by Lambda is

Received Event is: {'deviceId': 'test', 'applianceId': 'another test'}

For the custom payload expression, you can specify the payload in following format for JSON payloads.

"{
    \"variable1\": \"${$input.my_input.stringVariable}\", 
    \"variable2\": ${$input.my_input.numberVariable}
}"
  • #input.my_input.stringVariable is returning a string, and
  • #input.my_input.numberVariable is returning a number

This translates into the following when the DM is exported or described via API.

"\"{
    \\\"variable1\\\": \\\"${$input.my_input.stringVariable}\\\", 
    \\\"variable2\\\": ${$input.my_input.numberVariable}
}\""

May be you could try double-escaping the string values for creating the detector model from CLI.

AWS
已回答 2 年前
0

Maybe this one will help your IoT Event. It seems like there is an issue with the syntax of your content expression in the payload for the Lambda action. From the code example you provided, it appears that you are using a JSON object as the value for the contentExpression property.

To fix the issue, you can try updating your code as follows: { lambda: { functionArn: consumer.functionArn, payload: { contentExpression: "{"content": {"deviceId": "test", "applianceId": "another test"}}", type: 'JSON' } } }

In this updated code, I've added an additional level of nesting to the contentExpression value to ensure it represents a valid JSON object. The payload now has a "content" property which contains the device and appliance IDs.

Make sure to adjust the contentExpression property according to your desired JSON payload structure.

已回答 9 个月前

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

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

回答问题的准则