How can I query partition key without range key in dynamodb table?

Viewed 70

I have a dynamodb table defined as:

const params = {
      TableName: tableName,
      KeySchema: [
        { AttributeName: 'id', KeyType: 'HASH' }, // Partition key
        { AttributeName: 'timestamp', KeyType: 'RANGE' },
      ],
      AttributeDefinitions: [
        { AttributeName: 'id', AttributeType: 'S' },
        { AttributeName: 'timestamp', AttributeType: 'N' },
      ],
      ProvisionedThroughput: {
        ReadCapacityUnits: 10,
        WriteCapacityUnits: 10,
      },
    };
    return await dynamodb.createTable(params).promise();

The id is partition key and timestamp is sort key. And I use below query:

    const id = 'xxxx';
    const params = {
      TableName: this.tableName,
      ExpressionAttributeValues: {
        ':id': { S: id },
      },
      KeyConditionExpression: 'id = :id',
      ProjectionExpression: 'timestamp'
    };
    return this.dynamodbClient
      .query(params)
```'

when I run above query I got an error `ValidationException: The number of conditions on the keys is invalid`. I don't want to include sort key in the query. How can I make the query without sort key?
0 Answers
Related