Why am I getting a 'Cannot read properties of undefined' error while creating a DynamoDB put item action?

This topic was automatically generated from Slack. You can find the original thread here.

I’m creating an action for dynamodb put item but I’m getting an error. Think it’s related to JSON formatting but haven’t been able to pinpoint the issue after reading pipedream and dynamodb docs. Any tips?

Primary key: {{steps.trigger.event.body.phone}}

Item: {{JSON.stringify({phone: steps.trigger.event.body.phone, history: steps.chat.$return_value.original_messages_with_assistant_response})}}

TypeError

Cannot read properties of undefined (reading '0')

Stack trace

    at Object.visit (/tmp/__pdg__/dist/code/6c77ce4534e7e7249d2ac40b8ec83c93d3aa16558d1fc096a84aea583f4c9b73/node_modules/.pnpm/@aws-sdk+client-dynamodb@3.637.0/node_modules/@aws-sdk/client-dynamodb/dist-cjs/index.js:1003:36)
    at null.se_AttributeValue (/tmp/__pdg__/dist/code/6c77ce4534e7e7249d2ac40b8ec83c93d3aa16558d1fc096a84aea583f4c9b73/node_modules/.pnpm/@aws-sdk+client-dynamodb@3.637.0/node_modules/@aws-sdk/client-dynamodb/dist-cjs/index.js:2544:25)
    at null.null (/tmp/__pdg__/dist/code/6c77ce4534e7e7249d2ac40b8ec83c93d3aa16558d1fc096a84aea583f4c9b73/node_modules/.pnpm/@aws-sdk+client-dynamodb@3.637.0/node_modules/@aws-sdk/client-dynamodb/dist-cjs/index.js:2923:16)
    at Array.reduce (null:null:null)
    at null.se_PutItemInputAttributeMap (/tmp/__pdg__/dist/code/6c77ce4534e7e7249d2ac40b8ec83c93d3aa16558d1fc096a84aea583f4c9b73/node_modules/.pnpm/@aws-sdk+client-dynamodb@3.637.0/node_modules/@aws-sdk/client-dynamodb/dist-cjs/index.js:2919:32)
    at null.Item (/tmp/__pdg__/dist/code/6c77ce4534e7e7249d2ac40b8ec83c93d3aa16558d1fc096a84aea583f4c9b73/node_modules/.pnpm/@aws-sdk+client-dynamodb@3.637.0/node_modules/@aws-sdk/client-dynamodb/dist-cjs/index.js:2910:18)
    at null.applyInstruction (/tmp/__pdg__/dist/code/6c77ce4534e7e7249d2ac40b8ec83c93d3aa16558d1fc096a84aea583f4c9b73/node_modules/.pnpm/@smithy+smithy-client@3.2.0/node_modules/@smithy/smithy-client/dist-cjs/index.js:1092:27)
    at null.take (/tmp/__pdg__/dist/code/6c77ce4534e7e7249d2ac40b8ec83c93d3aa16558d1fc096a84aea583f4c9b73/node_modules/.pnpm/@smithy+smithy-client@3.2.0/node_modules/@smithy/smithy-client/dist-cjs/index.js:1060:5)
    at null.se_PutItemInput (/tmp/__pdg__/dist/code/6c77ce4534e7e7249d2ac40b8ec83c93d3aa16558d1fc096a84aea583f4c9b73/node_modules/.pnpm/@aws-sdk+client-dynamodb@3.637.0/node_modules/@aws-sdk/client-dynamodb/dist-cjs/index.js:2904:40)
    at null.se_PutItemCommand (/tmp/__pdg__/dist/code/6c77ce4534e7e7249d2ac40b8ec83c93d3aa16558d1fc096a84aea583f4c9b73/node_modules/.pnpm/@aws-sdk+client-dynamodb@3.637.0/node_modules/@aws-sdk/client-dynamodb/dist-cjs/index.js:1276:25)

Can you try without the JSON.stringify?

The type says string but the description says valid JSON, so yeah there is a confusion here

Try this for Item:

{ "phone": "{{steps.trigger.event.body.phone}}", "history": "{{steps.chat.$return_value.original_messages_with_assistant_response}}" }

Thanks for the quick reply. Turns out I didn’t understand DynamoDB requires a specific JSON structure: { "AttributeName": { "AttributeType": "AttributeValue" } }. Example: {"genre": { "S": "rock" }, "hits": { "N": "1050" } } Thought this was purely to show valid JSON. Thanks.

Ah yeah that too