1

I want to retrieve single item from DynamoDB but I'm unable to do that. I think I am missing something. I am able to scan the table using scan() function of boto but the fetching of a single item is not working. So it would be great if someone can tell me the correct way to do this.

models.py file:

import os
import boto
from boto import dynamodb2
from boto.dynamodb2.table import Table
from boto.dynamodb2.fields import HashKey, RangeKey, KeysOnlyIndex, GlobalAllIndex


AWS_ACCESS_KEY_ID = '****************'
AWS_SECRET_ACCESS_KEY = '***************************'
REGION = 'us-east-1'
TABLE_NAME = 'Users'

conn = dynamodb2.connect_to_region(REGION, aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY)

table = Table(
    TABLE_NAME,
    connection=conn
)

results = table.scan()


for dynamo_item in results:
    print dict(dynamo_item.items())

I've tried using following:

results = table.scan(scan_filter={'email':'new'})

but got this error

boto.dynamodb2.exceptions.UnknownFilterTypeError: Operator 'scan_filter' from 'scan_filter' is not recognized.

results = table.query_2(email = 'new')

boto.dynamodb2.exceptions.UnknownFilterTypeError: Operator 'email' from 'email' is not recognized.

results = table.get_item(email='new')

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'}

2
  • 1
    what is your table scheme? (hash/range key) Commented Apr 19, 2016 at 18:11
  • what is your hash key? (name/type)? Commented Apr 20, 2016 at 5:43

2 Answers 2

1

Try this:

results = table.query_2(email__eq = 'new')

You can also use the following:

__eq , __beginswith, __gte

Thanks to

@ing0: dynamodb row count via python, boto query

Source: DynamoDB2

Sign up to request clarification or add additional context in comments.

Comments

-1

If the table hash key is email then

results = table.get_item(email='new') should work.

Check if email is in type STRING (and not NUMBER) in the table scheme.

3 Comments

I've used this. You can look into my question. This command gives boto.dynamodb2.exceptions.ValidationException: ValidationException: 400 Bad Request
what is your email column type (as in dynamo db table)? maybe this is the reason.
You would write something like: results = table.get_item(Key={'email': 'new'})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.