-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_player_table.py
59 lines (51 loc) · 1.6 KB
/
create_player_table.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import boto3
def create_roster_table(client,resoruce):
try:
table = client.create_table(
TableName='Roster',
KeySchema=[
{
'AttributeName': 'playername',
'KeyType': 'HASH' # Partition key
},
{
'AttributeName': 'teamname',
'KeyType': 'RANGE' # Sort key
}
],
AttributeDefinitions=[
{
'AttributeName': 'playername',
'AttributeType': 'S'
},
{
'AttributeName': 'teamname',
'AttributeType': 'S'
},
],
ProvisionedThroughput={
'ReadCapacityUnits': 10,
'WriteCapacityUnits': 10
}
)
print("Creating table")
waiter = client.get_waiter('table_exists')
waiter.wait(TableName='Roster')
print("Table created")
return table
except ddb_exceptions.ResourceInUseException:
print("Table Exists")
if __name__ == '__main__':
#keeping my key hidden
client = boto3.client(
'dynamodb',
aws_access_key_id='****',
aws_secret_access_key='****',
)
resource = boto3.resource(
'dynamodb',
aws_access_key_id=='****',
aws_secret_access_key=='****',
)
ddb_exceptions = client.exceptions
roster_table = create_roster_table(client,ddb_exceptions)