【问题标题】:Getting AttributeError when trying to create DynamoDB table with global index using boto v2.25.0尝试使用 boto v2.25.0 创建具有全局索引的 DynamoDB 表时出现 AttributeError
【发布时间】:2014-03-11 07:15:54
【问题描述】:

我正在尝试按照示例 hereclass boto.dynamodb2.table.Table... 下的 # The full, minimum-extra-calls case. 块)创建具有全局二级索引的 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>))

【问题讨论】:

    标签: python amazon-dynamodb boto


    【解决方案1】:

    尝试以这种方式导入它:

    from boto.dynamodb2.table import Table
    

    我在 botocore 之上编写了一个也可以执行此操作的库:PynamoDB

    【讨论】:

    • 谢谢。在不使用 GSI 的情况下使用旧版本的 boto 时,我有以下语句序列:import boto... conn = boto.connect_dynamodb(... table = conn.create_table(... table.refresh(wait_for_active=True)。不知道新库里有没有类似refresh的东西?
    猜你喜欢
    • 2020-02-27
    • 2016-10-28
    • 2023-02-07
    • 2020-11-12
    • 1970-01-01
    • 2015-11-03
    • 2020-12-03
    • 2016-08-17
    • 2013-10-31
    相关资源
    最近更新 更多