尝试使用boto v2.25.0创建具有全局索引的DynamoDB表时获取AttributeError

时间:2014-02-12 18:43:26

标签: python amazon-dynamodb boto

我正在尝试使用示例here# The full, minimum-extra-calls case.下的class boto.dynamodb2.table.Table...块)创建一个带有全局二级索引的DynamoDB表。我正在使用boto版本2.25.0。确切的代码是:

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

我正在AttributeError: 'module' object has no attribute 'table'

我做错了什么?

==

编辑:根据Jharrod的答案,这里是代码的最终版本:

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 个答案:

答案 0 :(得分:1)

尝试以这种方式导入:

from boto.dynamodb2.table import Table

我已经编写了一个可以执行此操作的库,位于botocore之上:PynamoDB