Error: DynamoDB FilterExpression Not Working

Answered by Rafal Wilinski
Last updated: October 23rd, 2026
Solution
FilterExpression is applied after DynamoDB reads a page, so an empty result can mean the current page had no matches rather than the entire query having none. Inspect Count, ScannedCount and LastEvaluatedKey.
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, QueryCommand } from "@aws-sdk/lib-dynamodb";
const db = DynamoDBDocumentClient.from(new DynamoDBClient({}));
const page = await db.send(new QueryCommand({
TableName: "Orders",
KeyConditionExpression: "pk = :pk",
FilterExpression: "#status = :status",
ExpressionAttributeNames: { "#status": "status" },
ExpressionAttributeValues: { ":pk": "CUSTOMER#123", ":status": "OPEN" },
}));
console.log(page.Items, page.LastEvaluatedKey);For Query, put the queried partition and sort key constraints in KeyConditionExpression, not FilterExpression. Scan has no key condition and can filter key attributes. Compare stored types and exact values, including String versus Number and case differences, and define all aliases.
Follow LastEvaluatedKey even when Items is empty. Filters do not reduce read capacity already consumed. A GSI can filter only on attributes available in its projection; if the filter discards most items, consider an index that selects them by key.
See filter expressions and AWS documentation.
Other Common DynamoDB Errors (with Solutions)
- DynamoDB Local Cannot Create Preexisting Table
- dynamodb index not found
- failed to begin subsegment named 'amazondynamodbv2': segment cannot be found.
- DynamoDB Is Unsupported It Cannot Be Instantiated
- AWS Lambda DynamoDB Stream Error
- dynamodb: one or more parameter values were invalid: type mismatch for index key
- One or more parameter values were invalid: some AttributeDefinitions are not used
- error retrieving dynamodb table item serializationexception
- DynamoDB - The Security Token Included In The Request Is Invalid
- dynamodb unable to execute http request
- sls dynamodb install not working
- dynamodb could not load credentials from any providers
- error dynamodb streams must be enabled on the table
- dynamodb query not returning the full item
- DynamoDB Network Error: self signed certificate in chain
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today