Error: dynamodb put item not working

Answered by Rafal Wilinski
Last updated: October 23rd, 2026
Solution
PutItem can fail because the request is not awaited, required keys are missing, or low-level attribute values use the wrong representation. Capture the actual exception and use the API format that matches the client.
import { DynamoDBClient, PutItemCommand } from "@aws-sdk/client-dynamodb";
const db = new DynamoDBClient({});
export const handler = async () => {
await db.send(new PutItemCommand({
TableName: "People",
Item: { pk: { N: "1" }, name: { S: "Lakindu" } },
ReturnConsumedCapacity: "TOTAL",
}));
return { statusCode: 200, body: "Saved" };
};This table has a Number partition key. In low-level DynamoDB JSON, the value inside N is a string, even for an integer. With DynamoDBDocumentClient and PutCommand, use pk: 1 instead. Awaiting keeps the handler from returning before the write completes; it does not block all other JavaScript work.
An empty successful response does not mean failure. Read the same complete key from the base table with ConsistentRead enabled to verify it. A PutItem replaces the entire existing item at that key unless a condition rejects the write.
See writing items and AWS documentation.
Other Common DynamoDB Errors (with Solutions)
- dynamodb-admin is not recognized as an internal or external command
- dynamodb localhost not working
- dynamodb query not returning the full item
- DynamoDB missing items
- a socket operation was attempted to an unreachable network dynamodb
- DynamoDB sorting is not supported for scan expressions
- dynamodb cannot assign requested address
- Could not connect to the endpoint URL https:dynamodb.singapore.amazonaws.com
- DynamoDB Failed To Compute Node presentation
- CORS Error DynamoDB
- dynamodb validation error detected
- dynamodb item size limit error
- ValidationException: Invalid KeyConditionExpression: Attribute name is a reserved keyword;
- DynamoDB Contains not working
- is not authorized to perform dynamodb:* on resource
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today