2017-04-19 42 views
1

創建dynamodb表,我下面的文件創建表boto dynamodb documentation如何在python博託

message_table_schema = conn.create_schema(
     hash_key_name='forum_name', 
     hash_key_proto_value=str, 
     range_key_name='subject', 
     range_key_proto_value=str 
    ) 

table = conn.create_table(
     name='messages', 
     schema=message_table_schema, 
     read_units=10, 
     write_units=10 
    ) 

我想下面的代碼,但以下一些dynamodb對象怎麼不能找到create_schema表。

AttributeError: 'DynamoDBConnection' object has no attribute 'create_schema'

請讓我還是知道這個方法已經過時,如果有任何其他的方式來創建一個表。

+0

你是怎麼創建'conn'的? – franklinsijo

+0

conn = boto.dynamodb2.connect_to_region(args.region) –

回答

1

使用boto.dynamodb2創建的DynamoDBConnection沒有create_schema方法。它是boto.dynamodb.layer2.Layer2 API的一部分。

創建使用連接,

import boto.dynamodb 
conn = boto.dynamodb.connect_to_region(region) 

或者要創建一個表boto.dynamodb2,使用此create_table方法或Table代替。

+0

感謝您提到的用於dynamodb2的鏈接,我可以看到它的語法,但看不到任何示例。所以你有任何例子或任何相同的鏈接? –

+0

如果您需要如何傳遞'key_schema'的示例,請參閱'schema'如何傳遞給'create'示例[here](http://boto.cloudhackers.com/en/latest/ref/dynamodb2.html #boto.dynamodb2.table.Table)。 – franklinsijo

+1

感謝哥們,它的工作原理 –