Getting AttributeError when trying to create DynamoDB table with global index using boto v2.25.0

StackOverflow https://stackoverflow.com/questions/21736813

  •  10-10-2022
  •  | 
  •  

Question

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>))
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top