DynamoDB : The provided key element does not match the schema

user1635536 picture user1635536 · Sep 17, 2014 · Viewed 77.9k times · Source

Is there a way to get an item depending on a field that is not the hashkey?

Example

My Table Users: id (HashKey), name, email

And I want to retrieve the user having email as '[email protected]'

How this can be done?

I try this with boto:

user = users.get_item(email='[email protected]')

I get the following error:

'The provided key element does not match the schema'

Answer

Sean picture Sean · Nov 5, 2015

The following applies to the Node.js AWS SDK in the AWS Lambda environment:

This was a rough one for me. I ran into this problem when trying to use the getItem method. No matter what I tried I would continue to receive this error. I finally found a solution on the AWS forum: https://forums.aws.amazon.com/thread.jspa?threadID=208820

Inexplicably, the apparent solution conflicts with all AWS documentation that I can find.

Here is the code which worked for me:

var doc = require('dynamodb-doc');
var dynamo = new doc.DynamoDB();

var params = { }
params.TableName = "ExampleTable";
var key = { "ExampleHashKey": "1" };
params.Key = key;

dynamo.getItem(params, function(err, data) {
    if (err)
        console.log(err);
    else
        console.log(data)
});