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)
- AWS CLI DynamoDB Error Parsing Parameter
- DynamoDB No Regionendpoint Or Serviceurl Configured
- DynamoDB - The Security Token Included In The Request Is Invalid
- dynamodb cannot convert undefined to object
- DynamoDB Error 413
- could not unmarshal the value dynamodb
- missing required key 'key' in params dynamodb
- DynamoDB Invalid UpdateExpression Syntax Error Token
- dynamodb cannot read property 'push' of undefined
- ProvisionedThroughputExceededException DynamoDB
- DynamoDB Scan Not Working
- DynamoDB Local Docker Not Working
- sls dynamodb install not working
- dynamodb cannot create preexisting table
- dynamodb cannot read properties of undefined
Tired of switching accounts and regions? Use Dynobase.
Try 7-day free trial. No strings attached.
Product Features
DynamoDB Tools
DynamoDB Info
© 2025 Dynobase