close

[Solved] “The provided key element does not match the schema” error when getting an item from DynamoDB

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error “The provided key element does not match the schema” error when getting an item from DynamoDB in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How “The provided key element does not match the schema” error when getting an item from DynamoDB Error Occurs?

Today I get the following error “The provided key element does not match the schema” error when getting an item from DynamoDB in python.

How To Solve “The provided key element does not match the schema” error when getting an item from DynamoDB Error ?

  1. How To Solve “The provided key element does not match the schema” error when getting an item from DynamoDB Error ?

    To Solve “The provided key element does not match the schema” error when getting an item from DynamoDB Error Your table schema has both hash key and sort key defined. When using DynamoDB GetItem you must provide both of them, here is an excerpt from documentation

  2. “The provided key element does not match the schema” error when getting an item from DynamoDB

    To Solve “The provided key element does not match the schema” error when getting an item from DynamoDB Error Your table schema has both hash key and sort key defined. When using DynamoDB GetItem you must provide both of them, here is an excerpt from documentation

Solution 1

Your table schema has both hash key and sort key defined. When using DynamoDB GetItem you must provide both of them, here is an excerpt from documentation

For the primary key, you must provide all of the attributes. For example, with a simple primary key, you only need to provide a value for the partition key. For a composite primary key, you must provide values for both the partition key and the sort key.

So given your example, here is how get_item parameters should look like:

response = table.get_item(Key={'userId': "user2873", 'createdAt': "1489376547"})

Solution 2

One other thing that works is the following code below:

from boto3.dynamodb.conditions import Key

result = table.query(
        KeyConditionExpression=Key('userId').eq('user2873')
    )

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read