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

1 Answer 1

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.

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

1 Comment

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?

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.