【发布时间】:2019-09-19 19:37:53
【问题描述】:
我想从 DynamoDB 中检索单个项目,但我无法做到。我想我错过了一些东西。我可以使用 boto 的 scan() 函数扫描表,但单个项目的获取不起作用。因此,如果有人能告诉我正确的方法,那就太好了。
models.py 文件:
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())
我尝试使用以下方法:
results = table.scan(scan_filter={'email':'new'})
但收到此错误
boto.dynamodb2.exceptions.UnknownFilterTypeError:无法识别来自“scan_filter”的运算符“scan_filter”。
results = table.query_2(email = 'new')
boto.dynamodb2.exceptions.UnknownFilterTypeError:无法识别来自“电子邮件”的操作员“电子邮件”。
results = table.get_item(email='new')
boto.dynamodb2.exceptions.ValidationException: ValidationException: 400 Bad Request {u'message': u'提供的关键元素与架构不匹配', u'__type': u'com.amazon.coral.validate#ValidationException'}
【问题讨论】:
-
你的餐桌方案是什么? (哈希/范围键)
-
你的哈希键是什么? (名称/类型)?
标签: python amazon-web-services amazon-dynamodb boto