mackwerk
mackwerk

Reputation: 1687

DynamoDB2 and Boto 2.9.5 bad request on batch query and single item get

I am having trouble doing any single or batch query with boto 2.9.5 using the DynamoDB2 API

I need to do a batch query like this:

one_org = Table('[table-name]').batch_get(keys=[
        {'key': '[user-id-hash]'},
        {'key': '[user-id-hash]'},
        {'key': '[user-id-hash]'},
        {'key': '[user-id-hash]'},
    ])

for user in one_org:
    for key, value in user.items():
        print key, value

I keep getting this exception:

boto.dynamodb2.exceptions.ValidationException: ValidationException: 400 Bad Request
{
    u'message': u'The provided key element does not match the schema', 
    u'__type': u'com.amazon.coral.validate#ValidationException'
}

Given this message I'd think there'd be a problem with the name of the key, but our key is called key, so it doesn't make any sense to me.

I included the stack trace below:

Traceback (most recent call last):
  File "aws/interfaces.py", line 38, in <module>
    for user in one_org:
  File "/home/kasper/Falcon/thenest/venv/local/lib/python2.7/site-packages/boto/dynamodb2/results.py", line 59, in next
    self.fetch_more()
  File "/home/kasper/Falcon/thenest/venv/local/lib/python2.7/site-packages/boto/dynamodb2/results.py", line 141, in fetch_more
    results = self.the_callable(*args, **kwargs)
  File "/home/kasper/Falcon/thenest/venv/local/lib/python2.7/site-packages/boto/dynamodb2/table.py", line 949, in _batch_get
    raw_results = self.connection.batch_get_item(request_items=items)
  File "/home/kasper/Falcon/thenest/venv/local/lib/python2.7/site-packages/boto/dynamodb2/layer1.py", line 152, in batch_get_item
    body=json.dumps(params))
  File "/home/kasper/Falcon/thenest/venv/local/lib/python2.7/site-packages/boto/dynamodb2/layer1.py", line 1479, in make_request
    retry_handler=self._retry_handler)
  File "/home/kasper/Falcon/thenest/venv/local/lib/python2.7/site-packages/boto/connection.py", line 852, in _mexe
    status = retry_handler(response, i, next_sleep)
  File "/home/kasper/Falcon/thenest/venv/local/lib/python2.7/site-packages/boto/dynamodb2/layer1.py", line 1518, in _retry_handler
    response.status, response.reason, data)
boto.dynamodb2.exceptions.ValidationException: ValidationException: 400 Bad Request
{u'message': u'The provided key element does not match the schema', u'__type': u'com.amazon.coral.validate#ValidationException'}

Upvotes: 3

Views: 5680

Answers (2)

Pasada
Pasada

Reputation: 326

I was facing the same issue this morning. If you have defined a RangeKey in your schema then you need to specify that as well. If you don't want to specify the RangeKey and only get the item using HashKey then consider removing the RangeKey.

Upvotes: 11

garnaat
garnaat

Reputation: 45856

The error is saying that the value(s) provided do not match the type defined in the schema. I don't know what your schema is but, as an example, if the schema defined the primary key (called key in your case) as a string and you provided an integer value or vice-versa you would get this error.

Check your schema and make sure you are passing in the right type of value for your query.

Upvotes: 3

Related Questions