dynobase-icon
Dynobase

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

Rafal Wilinski

Answered by Rafal Wilinski

Last updated: October 23rd, 2026

Solution

Invalid KeyConditionExpression: Attribute name is a reserved keyword means an attribute name in the expression conflicts with DynamoDB's expression language. Keep the stored name and reference it through an ExpressionAttributeNames alias.

For a table whose partition key is pk and sort key is timestamp, alias the sort key while retaining the partition-key equality:

import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, QueryCommand } from "@aws-sdk/lib-dynamodb";

const db = DynamoDBDocumentClient.from(new DynamoDBClient({}));

const result = await db.send(new QueryCommand({
  TableName: "Events",
  KeyConditionExpression: "#pk = :pk AND #ts BETWEEN :start AND :end",
  ExpressionAttributeNames: { "#pk": "pk", "#ts": "timestamp" },
  ExpressionAttributeValues: {
    ":pk": "USER#123", ":start": "2026-10-01", ":end": "2026-10-31",
  },
}));

This example assumes string sort keys stored in a consistent sortable date format. Match the stored type and desired boundaries in your application. If timestamp is an ordinary non-key attribute, put that condition in FilterExpression instead, or use an index designed for the lookup.

Aliases begin with #; value placeholders begin with :. Define each one in the matching map and use the alias everywhere that attribute appears. The same approach works for FilterExpression, ProjectionExpression and UpdateExpression. Use the reserved-word checker to identify other conflicting names.

See query guidance and AWS documentation.

Dynobase is a Professional GUI Client for DynamoDB

Start your 7-day free trial today

Product Features

Download
/
Pricing
/
Member Portal
/
Privacy
/
EULA
/
Twitter
© 2026 Dynobase
+
Still using AWS DynamoDB Console?
Try Dynobase to accelerate your DynamoDB workflow. Start your 7-day free trial today.