boto python dynamodb scan attributes_to_get

时间:2014-06-03 02:17:23

标签: python amazon-dynamodb

民间,   boto的文档充其量是模糊的,为什么这个操作不起作用?

from boto.dynamodb2.table import Table
import time

print "Scanning Existing Database"

myTable = Table('myTable')

start = time.clock()

my_query = myTable.scan(scan_filter=None, attributes_to_get=['something'])
results = []
for x in my_query:
    results.append(x['something'])

elapsed = (time.clock() - start)
print "Scan Operation took",elapsed
print len(results)

为什么这样做:

#!/bin/env python

import boto
db = boto.connect_dynamodb()

import time

print "Scanning Existing Database"

table = db.get_table('current_fhv_drivers')

start = time.clock()

all_query = table.scan(attributes_to_get=['something'])
results = []
for x in all_query:
    results.append(x['something'])

elapsed = (time.clock() - start)
print "Scan Operation took",elapsed
print len(results)

2 个答案:

答案 0 :(得分:0)

似乎您在创建连接之前尝试获取表。尝试:

import boto
import boto.dynamodb2
from boto.dynamodb2.table import Table

conn = boto.dynamodb2.connect_to_region(
    'us-east-1',
    aws_access_key_id=AWS_ACCESS_KEY_ID,
    aws_secret_access_key=AWS_SECRET_ACCESS_KEY
)
myTable = Table('myTable', connection=conn)

答案 1 :(得分:0)

如果在.boto文件中正确设置配置,则必须使用第一个代码示例。 它适用于我的任务。