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年前677ビュー
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.

回答済み 8ヶ月前

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

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

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

関連するコンテンツ