how.wtf

DynamoDB error: key element does not match the schema

· Thomas Taylor

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  "pk": "test_pk",
3  "sk": "test_sk"
4}

Python Boto3:

 1import boto3
 2
 3dynamodb = boto3.resource("dynamodb")
 4table = dynamodb.Table("test")
 5table.get_item(
 6    Key={
 7        "pk": "test_pk",
 8        "sk": "test_sk"
 9    }
10)
11
12table.delete_item(
13    Key={
14        "pk": "test_pk",
15        "sk": "test_sk",
16        "other": "test"
17    }
18)

#aws   #dynamodb  

Reply to this post by email ↪