Hey everyone! I'm having a problem with my Lambda function (NodeJS 22.x, running in us-west-2) that keeps failing to add items to DynamoDB. The error it gives is: "One or more parameter values were invalid: Type mismatch for key pk expected: S actual: M". When I check the logs, the request looks something like this: { "TableName": "ranking", "Item": { "pk": "20250630_overall-rank", "sk": "p1967", "expirationSec": ... "data": ... } }. I'm using DynamoDBDocumentClient for the insertion. The strange thing is, this code has been working just fine for years, but it suddenly started failing yesterday. It's also inconsistent: sometimes it works for a few items, but when I try inserting around 2000 items with about 10 concurrent requests, I get this error randomly for some items. The pk definitely looks like a string. If there was a formatting issue, I would expect consistent failures, right? I'm starting to think there might be a bug on AWS's side. Any help would be greatly appreciated!
4 Answers
It might be worth checking this GitHub issue: https://github.com/awslabs/dynamodb-document-js-sdk/issues/17. It could provide some insight if it’s similar to what you're facing.
Are you using SDK v3 for your Node code? Sometimes certain features can cause unexpected issues if you're on an older version.
From the error message, it seems like one of the records might have a pk that is actually an object instead of a string. I'd suggest taking a closer look at your input data. Also, consider implementing a queue to catch failed inserts. Using a dead letter queue can be a good practice for diagnosing issues like this and reducing write density problems.
Have you checked if DynamoDB might be throttling your requests? If you're using on-demand provisioning, that could potentially lead to issues. Just a thought! You can find more about throttling in AWS's documentation.
Yeah, I am on-demand provisioning, but throttling usually gives a different error, right? I've had throttling issues before, but this doesn’t seem like that.
I’m working with the DynamoDBDocumentClient and a straightforward JSON-like object, so I don’t think conversion issues are causing this. Plus, if it were an issue with the data format, wouldn’t it fail consistently?