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 delete fails
- dynamodb item size limit error
- dynamodb the table does not have the specified index
- DynamoDB Hostname Cannot Be Null
- sls dynamodb install not working
- dynamodb-admin not working
- a cell may contain a maximum of 30000 characters dynamodb
- DynamoDB Network Error: self signed certificate in chain
- dynamodb type custid is not supported
- DynamoDB Delete Method Not Working For The First Time
- dynamodb property projection cannot be empty
- dynamodb does not support null values
- dynamodb condition does not exist
- error dynamodb streams must be enabled on the table
- AWS CLI DynamoDB Error Parsing Parameter
Tired of switching accounts and regions? Use Dynobase.
Try 7-day free trial. No strings attached.
Product Features
DynamoDB Tools
DynamoDB Info
© 2025 Dynobase