0
votes

Folks, The docs for boto are vague at best, why is this operation not working?

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)

why does this work:

#!/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

2 Answers

0
votes

Seems that you're trying to get a table before creating a connection. Try:

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)
0
votes

First code example must work if you properly set configs in .boto file. It works for my tasks.