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 string set cannot be empty
- DynamoDB Local Docker Not Working
- resourcenotfoundexception dynamodb nodejs
- dynamodb: one or more parameter values were invalid: type mismatch for index key
- dynamodb cannot read properties of undefined
- Unable to start DynamoDB Local process
- aws lambda dynamodb nodejs not working after few puts
- dynamodb does not accept empty set
- com amazonaws services dynamodbv2 model resourcenotfoundexception
- DynamoDB Scan Not Working
- DynamoDB Duplicate Key Error
- DynamoDB Is Unsupported It Cannot Be Instantiated
- dynamodb cannot create preexisting table
- ConfigError: Missing region in config
- DynamoDB No Provisioned Throughput specified for the table
Login to the AWS Console less. Use Dynobase.
First 7 days are. No credit card needed.
Product Features
DynamoDB Tools
DynamoDB Info
© 2025 Dynobase