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?

demandé il y a 2 ans709 vues
2 réponses
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
répondu il y a 2 ans
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.

répondu il y a 9 mois

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions