Error: ValidationException: Invalid KeyConditionExpression: Attribute name is a reserved keyword;

Answered by Rafal Wilinski
Solution
DynamoDB has a list of reserved keywords that you cannot use in your queries or scans directly. If you need to write an expression that contains one of them, you need to use ExpressionAttributeNames to replace reserved word with a placeholder. For example, this query with reserved keyword:
params = { TableName : ‘MY_TABLE’, FilterExpression: "timestamp BETWEEN :startDate AND :endDate", ExpressionAttributeValues: { ":startDate": ""+startDate, ":endDate": ""+endDate } }
Replace with:
params = { TableName : ‘MY_TABLE’, FilterExpression: "#dynobase_timestamp BETWEEN :startDate AND :endDate", ExpressionAttributeValues: { ":startDate": startDate, ":endDate": endDate }, ExpressionAttributeNames: { "#dynobase_timestamp": "timestamp" } }
Other Common DynamoDB Errors (with Solutions)
- DynamoDB batch write is not working
- dynamodb the parameter cannot be converted to a numeric value
- dynamodb system errors metric
- can't pickle thread.lock objects typeerror boto3 python dynamodb
- dynamodb localhost not working
- dynamodb property projection cannot be empty
- dynamodb unable to execute http request
- dynamodb trigger no records processed
- dynamodb problem function call failed
- dynamodb global secondary index not working
- dynamodb global secondary index does not project
- dynamodb condition does not exist
- dynamodb unable to find storage information for property
- DynamoDB error 400
- a cell may contain a maximum of 30000 characters dynamodb
Tired of AWS Console? Try Dynobase.
Try 7-day free trial. No strings attached.
Product Features
DynamoDB Tools
DynamoDB Info
© 2025 Dynobase