ValidationException: The provided key element does not match the schema

TL;DR — The key you passed doesn't line up with the table's declared key schema: wrong attribute name, wrong type (string vs number), or a missing sort key. Match the request's key exactly to KeySchema + AttributeDefinitions.

What it means

Every DynamoDB item is addressed by its primary key — a partition key, optionally plus a sort key — with fixed names and types set at table creation. GetItem, DeleteItem, UpdateItem and each Key in a batch must supply exactly that key. This error fires when the supplied key doesn't match.

Why it happens

  • Wrong attribute name — you passed id but the table's key is pk.
  • Wrong type — the key is defined as Number (N) but you sent a String ("123"), or vice-versa. "123" and 123 are different keys to DynamoDB.
  • Missing the sort key — the table has a composite key but your Key only has the partition key (or an extra sort key on a partition-only table).
  • Extra attributes in Key — the Key map must contain only the key attributes, nothing else.

How to fix it

  1. Check the table's key schema (DescribeTableKeySchema + AttributeDefinitions), then make the request's Key match name-for-name and type-for-type.
  2. Fix number/string mismatches. If the key is N, pass a JS number (the Document Client marshals it); with the low-level client use {N: '123'}, not {S: '123'}.
  3. Supply the full composite key. Composite-key tables need both partition and sort key on every item-based call.

Example

// Table: Users, key = { pk (S) HASH, sk (S) RANGE }
import {DynamoDBClient} from '@aws-sdk/client-dynamodb';
import {DynamoDBDocumentClient, GetCommand} from '@aws-sdk/lib-dynamodb';

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

//  both key parts, correct names/types
await doc.send(new GetCommand({TableName: 'Users', Key: {pk: 'USER#1', sk: 'PROFILE'}}));

//  missing sort key → "provided key element does not match the schema"
// await doc.send(new GetCommand({TableName: 'Users', Key: {pk: 'USER#1'}}));

Console なしで DynamoDB を扱う

DynoTable は DynamoDB 向けの高速なデスクトップクライアントです — テーブルを閲覧し、SQL スタイルのクエリを実行し、アイテムをローカルで編集できます。