Amazon DynamoDB (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What are Partition Keys (HASH) and Sort Keys (RANGE) in DynamoDB?
junior LevelCode ExampleDynamoDB
In Simple Words: Every DynamoDB item must have a primary key. It can be simple or composite:
- Simple Primary Key (Partition Key only): DynamoDB hashes the partition key value to determine the exact internal storage partition where the item lives.
- Composite Primary Key (Partition Key + Sort Key): All items sharing the same partition key are stored together on the same physical partition, sorted ascending by the sort key (B-tree ordering).
typescript
// Query items sharing the same partition key within a sort key range:
import { DynamoDBClient, QueryCommand } from "@aws-sdk/client-dynamodb";
const client = new DynamoDBClient({});
const command = new QueryCommand({
TableName: "SensorReadings",
KeyConditionExpression: "deviceId = :id AND timestamp BETWEEN :start AND :end",
ExpressionAttributeValues: {
":id": { S: "sensor_042" },
":start": { S: "2026-01-01T00:00:00Z" },
":end": { S: "2026-01-02T00:00:00Z" }
}
});