Error: DynamoDB Contains not working

Answered by Rafal Wilinski
Last updated: October 23rd, 2026
Solution
contains works on a String, Set, or List. It checks a substring for strings and membership for collections. It is allowed in filter and condition expressions, not in a Query KeyConditionExpression. A Number attribute itself is not a searchable collection.
import boto3
from boto3.dynamodb.conditions import Key, Attr
table = boto3.resource("dynamodb", region_name="us-east-1").Table("Orders")
page = table.query(
KeyConditionExpression=Key("pk").eq("CUSTOMER#123"),
FilterExpression=Attr("tags").contains("priority"),
)
print(page.get("Items", []))For a string set, pass one string, not a set containing that string. For a number set, pass a number of the appropriate client representation. For strings, matching is case-sensitive. To search a nested field, address that field rather than passing an entire map to contains.
Filters run after the key-based read and do not reduce its read capacity. Continue through LastEvaluatedKey even when a page contains no matches. Use begins_with for a supported sort-key prefix condition; contains cannot turn an arbitrary substring search into an indexed Query.
See expression builder and AWS documentation.
Other Common DynamoDB Errors (with Solutions)
- DynamoDB Query Limit Not Working
- failed to list tables not authorized dynamodb
- DynamoDB Expression Not Null
- dynamodb converter not found for enhancedtype
- DynamoDB Scan Not Working
- dynamodb unable to execute http request
- DynamoDB cannot do operations on a non-existent table
- dynamodb table not exists
- why is the GSI dynamodb not showing item count
- DynamoDB Duplicate Key Error
- DynamoDB string set cannot be empty
- AWS DynamoDB errors ResourceNotFoundException
- dynamodb table did not stabilize
- dynamodb list_append if_not_exists not working
- DynamoDB stream not working
Dynobase is a Professional GUI Client for DynamoDB
Start your 7-day free trial today
Product Features
DynamoDB Tools
- SSH GUI Client
- Chat With Cloud
- MongoDB GUI Client
- AWS Cost Monitoring
- DynamoDB Query Builder
- DynamoDB Code Examples
- DynamoDB Node.js Queries
- DynamoDB JSON Converter
- DynamoDB UUID Generator
- DynamoDB Local Admin GUI
- DynamoDB Pricing Calculator
- DynamoDB Single-Table Design
- Best DynamoDB GUI Clients
- Dynobase vs DynoTable