dynobase-icon
Dynobase

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

Rafal Wilinski

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" }
        }
        

Login to the AWS Console less. Use Dynobase.

First 7 days are. No credit card needed.

Product Features

Download
/
Changelog
/
Pricing
/
Member Portal
/
Privacy
/
EULA
/
Twitter
/
Affiliates & Influencers
© 2025 Dynobase
+
Login to the AWS Console less.
Try Dynobase to accelerate your DynamoDB workflow. Start your 7-day free trial today.