DynamoDB Error

Hi,

I want to use DynamoDB on AWS for collecting error from the error Workflow.

Here is my workflow :

{
  "nodes": [
    {
      "parameters": {
        "tableName": "N8N_AWS_test",
        "dataToSend": "autoMapInputData",
        "additionalFields": {}
      },
      "name": "AWS DynamoDB",
      "type": "n8n-nodes-base.awsDynamoDb",
      "typeVersion": 1,
      "position": [
        850,
        550
      ],
      "credentials": {
        "aws": "AWS N8N Test DynamoDB"
      }
    },
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {},
      "name": "Error Trigger",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [
        250,
        550
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "Timestamp",
              "value": "={{$json[\"Timestamp\"]}}"
            },
            {
              "name": "Workflow ID",
              "value": "={{$json[\"workflow\"][\"id\"]}}"
            },
            {
              "name": "Workflow Name",
              "value": "={{$json[\"workflow\"][\"name\"]}}"
            },
            {
              "name": "Execution ID",
              "value": "={{$json[\"execution\"][\"id\"]}}"
            },
            {
              "name": "Execution URL",
              "value": "={{$json[\"execution\"][\"url\"]}}"
            },
            {
              "name": "lastNodeExecuted",
              "value": "={{$json[\"execution\"][\"lastNodeExecuted\"]}}"
            },
            {
              "name": "Execution mode",
              "value": "={{$json[\"execution\"][\"mode\"]}}"
            },
            {
              "name": "Execution retryOf",
              "value": "={{$json[\"execution\"][\"retryOf\"]}}"
            },
            {
              "name": "Execution error stack",
              "value": "={{$json[\"execution\"][\"error\"][\"stack\"]}}"
            },
            {
              "name": "Execution error message",
              "value": "={{$json[\"execution\"][\"error\"][\"message\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        650,
        550
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "Timestamp",
              "value": "={{new Date().toISOString()}}"
            }
          ],
          "number": []
        },
        "options": {}
      },
      "name": "Add Timestamp",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        450,
        550
      ]
    },
    {
      "parameters": {
        "tableName": "N8N_AWS_test",
        "dataToSend": "autoMapInputData",
        "additionalFields": {}
      },
      "name": "AWS DynamoDB",
      "type": "n8n-nodes-base.awsDynamoDb",
      "typeVersion": 1,
      "position": [
        850,
        550
      ],
      "credentials": {
        "aws": "AWS N8N Test DynamoDB"
      }
    }
  ],
  "connections": {
    "Error Trigger": {
      "main": [
        [
          {
            "node": "Add Timestamp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "AWS DynamoDB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Timestamp": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

On AWS DynamoDB, i have configured :

  • Partition Key : Workflow ID (String)
  • Sort Key : Timestamp (String)

I got the following error that I don’t understand has evrything is defined as string :

ERROR: AWS error response [400]: 400 - “{”__type":“com.amazon.coral.validate#ValidationException”,“message”:“One or more parameter values were invalid: Type mismatch for key Workflow ID expected: S actual: N”}

Any idea ?

Hi @mcc37,

At a guess I would say it is expecting a string but getting a number although I wouldn’t have thought that would matter.

There are a few google hits for Type mismatch for key xxxx expected: S actual: N” though.

Hi @jon

It looks quite strange. I did recreate the DynamoDB table with N as type for Workflow ID and it works.

I seems like AWS is guessing the type when request by n8n node rather than taking into account the type set within n8n.

It’s gonna work for my use case, but is it the expected behavior ?

That is a good question, I have never used it but it does look interesting. I might have to set it up and have a play at some point.

I want to use DynamoDB for event or error logging as AWS provides it free up to 25 Gb.

I did setup a Error workflow to catch execution errors. It looks like this :

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {},
      "name": "Error Trigger",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [
        250,
        550
      ]
    },
    {
      "parameters": {
        "tableName": "N8N_AWS_test",
        "dataToSend": "autoMapInputData",
        "additionalFields": {}
      },
      "name": "AWS DynamoDB",
      "type": "n8n-nodes-base.awsDynamoDb",
      "typeVersion": 1,
      "position": [
        850,
        550
      ],
      "notesInFlow": false,
      "credentials": {
        "aws": "AWS N8N Test DynamoDB"
      }
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "Timestamp",
              "value": "={{new Date().toISOString()}}"
            }
          ],
          "number": [
            {
              "name": "TTL",
              "value": "={{Math.floor(new Date().getTime()/1000.0)+2592000}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Add Timestamp & TTL",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        450,
        550
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "Timestamp",
              "value": "={{$json[\"Timestamp\"]}}"
            },
            {
              "name": "Workflow ID",
              "value": "={{$json[\"workflow\"][\"id\"]}}"
            },
            {
              "name": "Workflow Name",
              "value": "={{$json[\"workflow\"][\"name\"]}}"
            },
            {
              "name": "Execution ID",
              "value": "={{$json[\"execution\"][\"id\"]}}"
            },
            {
              "name": "Execution URL",
              "value": "={{$json[\"execution\"][\"url\"]}}"
            },
            {
              "name": "lastNodeExecuted",
              "value": "={{$json[\"execution\"][\"lastNodeExecuted\"]}}"
            },
            {
              "name": "Execution mode",
              "value": "={{$json[\"execution\"][\"mode\"]}}"
            },
            {
              "name": "Execution retryOf",
              "value": "={{$json[\"execution\"][\"retryOf\"]}}"
            },
            {
              "name": "Execution error stack",
              "value": "={{$json[\"execution\"][\"error\"][\"stack\"]}}"
            },
            {
              "name": "Execution error message",
              "value": "={{$json[\"execution\"][\"error\"][\"message\"]}}"
            }
          ],
          "number": [
            {
              "name": "TTL",
              "value": "={{$json[\"TTL\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Prepare data",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        650,
        550
      ],
      "notesInFlow": true,
      "notes": "Prepare data for database"
    }
  ],
  "connections": {
    "Error Trigger": {
      "main": [
        [
          {
            "node": "Add Timestamp & TTL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Timestamp & TTL": {
      "main": [
        [
          {
            "node": "Prepare data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare data": {
      "main": [
        [
          {
            "node": "AWS DynamoDB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

With the TTL feature of DynamoDB, you decide for each entry how long it lives.

I’m gonna do the same to create events to keep a log entry for some workflows.

I find it pretty cool.

I just had a look. You used auto-map but provided the input incorrectly. I would recommend using the other option and reference the values using expression. With auto-map the input it’s not a key-value pair but a key-object pair.

2 Likes