def build_table(session, table_name, account_data):
client = session.client('dynamodb')
try:
t = client.create_table(TableName=table_name,
KeySchema=[
{
'AttributeName': 'name',
'KeyType': 'HASH'
}
],
AttributeDefinitions=[
{
'AttributeName': 'name',
'AttributeType': 'S'
}
],
ProvisionedThroughput={
'ReadCapacityUnits': 10,
'WriteCapacityUnits': 1
},
)
resource = session.resource('dynamodb')
print "+ Created Dynamodb Table: {}... Waiting for table creation to propagate before inserting items".format(table_name)
sleep(15)
table = resource.Table(table_name)
for i in account_data:
table.put_item(Item=i)
except ClientError as e:
raise e
return t['TableDescription']['TableName']
评论列表
文章目录