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

无人久伴 提交于 2019-12-13 04:35:15

问题


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:


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.



来源:https://stackoverflow.com/questions/21736813/getting-attributeerror-when-trying-to-create-dynamodb-table-with-global-index-us

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!