Error: dynamodb cannot read properties of undefined

Answered by Rafal Wilinski
Last updated: October 23rd, 2026
Solution
Cannot read properties of undefined is a JavaScript TypeError, not a DynamoDB service exception. The stack trace identifies which object was missing when your code tried to read a property.
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, QueryCommand } from "@aws-sdk/lib-dynamodb";
const db = DynamoDBDocumentClient.from(new DynamoDBClient({}));
const response = await db.send(new QueryCommand({
TableName: "Orders",
KeyConditionExpression: "pk = :pk",
ExpressionAttributeValues: { ":pk": "CUSTOMER#123" },
}));
const first = response.Items?.[0];
if (first === undefined) {
console.log("No item on this page");
} else {
console.log(first.sk);
}Defaulting Items to [] does not make Items[0] exist. A filtered page can be empty while LastEvaluatedKey indicates more pages. GetCommand returns a single optional Item, not Items. Check projections when a nested property is missing from an otherwise valid item.
Await the request and do not swallow SDK failures and then continue with an undefined result. Optional chaining is useful when absence is expected; otherwise validate the data and report the unexpected shape rather than hiding the bug.
See JavaScript examples and AWS documentation.
Other Common DynamoDB Errors (with Solutions)
- DynamoDB local error spawn java ENOENT
- a socket operation was attempted to an unreachable network dynamodb
- DynamoDB query is slow
- DynamoDB Update Not Working
- com amazonaws services dynamodbv2 model resourcenotfoundexception
- boto3 dynamodb unable to locate credentials
- dynamodb attribute does not exist
- dynamodb-admin is not recognized as an internal or external command
- DynamoDB attribute not empty
- could not unmarshal the value dynamodb
- DynamoDB is not showing all columns
- DynamoDB Is Unsupported It Cannot Be Instantiated
- dynamodb put function not working
- dynamodb-admin command not found
- dynamodb unable to locate property for key attribute
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today