1

I am trying to create a DynamoDB table with a global secondary index following the example here (The # The full, minimum-extra-calls case. block under class boto.dynamodb2.table.Table...). I am using boto version 2.25.0. The exact code is:

import boto
from boto import dynamodb2
table = boto.dynamodb2.table.Table('myTable', 
       schema=[HashKey('firstKey')], 
       throughput={'read':5,'write':2},
       global_indexes=[GlobalAllIndex('secondKeyIndex',parts=[HashKey('secondKey')],throughput={'read':5,'write':3})], 
       connection=dynamodb2.connect_to_region('us-east-1',aws_access_key_id=<MYID>,aws_secret_access_key=<MYKEY>))

I am getting AttributeError: 'module' object has no attribute 'table'

What am I doing wrong?

======

EDIT: Based on Jharrod's answer below, here's the final version of the code:

import os
import boto
from boto.dynamodb2.table import Table, HashKey, GlobalAllIndex
table = Table.create('myTable', 
    schema=[HashKey('firstKey')], 
    throughput={'read':5,'write':2},
    global_indexes=[GlobalAllIndex('secondKeyIndex',parts=[HashKey('secondKey')],throughput={'read':5,'write':3})], 
    connection=boto.dynamodb2.connect_to_region('us-east-1',aws_access_key_id=<MYID>,aws_secret_access_key=<MYKEY>))
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
I Z
  • 5,719
  • 19
  • 53
  • 100

1 Answers1

1

Trying importing it this way:

from boto.dynamodb2.table import Table

I've written a library that can do this as well, on top of botocore: PynamoDB.

Jharrod LaFon
  • 545
  • 4
  • 6
  • Thanks. When using an older version of `boto` without GSI, I had the following sequence of statements: `import boto... conn = boto.connect_dynamodb(... table = conn.create_table(... table.refresh(wait_for_active=True)`. Do you know if there is something similar to `refresh` in the new library? – I Z Feb 13 '14 at 16:26