DynamoDB error: key element does not match the schema

The provided key element does not match the schema occurs when getting or deleting a record without providing all the proper key elements.

How to fix the error

If your DynamoDB schema includes a partition/hash key and a range/sort key, you must specify both attributes.

Given the schema:

1
2
3
4
{
  "pk": "test_pk",
  "sk": "test_sk"
}

Python Boto3:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import boto3

dynamodb = boto3.resource("dynamodb")
table = dynamodb.Table("test")
table.get_item(
    Key={
        "pk": "test_pk",
        "sk": "test_sk"
    }
)

table.delete_item(
    Key={
        "pk": "test_pk",
        "sk": "test_sk",
        "other": "test"
    }
)