Filter expressions help you pick only the items you want from a database query or scan. They act like a sieve, letting through just the data that matches your rules.
Filter expressions in DynamoDB
FilterExpression = "attribute_name operator :value" ExpressionAttributeValues = {":value": {"S"|"N"|"BOOL"|... : value}} Example: FilterExpression = "Price < :maxPrice" ExpressionAttributeValues = {":maxPrice": {"N": "20"}}
Filter expressions are used with Scan or Query operations in DynamoDB.
They do not reduce the read capacity used; they filter results after reading.
FilterExpression = "Price < :maxPrice" ExpressionAttributeValues = {":maxPrice": {"N": "20"}}
FilterExpression = "contains(Category, :cat)" ExpressionAttributeValues = {":cat": {"S": "Books"}}
FilterExpression = "Status = :status" ExpressionAttributeValues = {":status": {"S": "shipped"}}
This command scans the 'Products' table and returns only items where the Price is less than 20. It shows the ProductId and Price for each matching item.
aws dynamodb scan \ --table-name Products \ --filter-expression "Price < :maxPrice" \ --expression-attribute-values '{":maxPrice":{"N":"20"}}' \ --projection-expression "ProductId, Price"
Filter expressions only filter results after DynamoDB reads the data, so they do not reduce read capacity usage.
Use ExpressionAttributeValues to safely pass values and avoid injection issues.
You can combine multiple conditions using AND, OR, and parentheses in filter expressions.
Filter expressions help you get only the data you want from a scan or query.
They use simple conditions on attributes like equals, less than, or contains.
Remember, filtering happens after reading, so it does not save read capacity.