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년 전702회 조회
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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인