-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_table.py
More file actions
53 lines (46 loc) · 1.6 KB
/
create_table.py
File metadata and controls
53 lines (46 loc) · 1.6 KB
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
from __future__ import print_function # Python 2/3 compatibility
import boto3
import tconf
#url="https://dynamodb.eu-central-1.amazonaws.com"
#region="eu-central-1"
dynamodb = boto3.resource('dynamodb', region_name=tconf.region, endpoint_url=tconf.url)
print ("Creating 'Temperature' table...")
try:
table = dynamodb.create_table(
TableName = 'Temperature',
KeySchema = [
{ 'AttributeName': 'Thermometer', 'KeyType': 'HASH' }, # //Partition key
{ 'AttributeName': 'GetDate', 'KeyType': 'RANGE' } #//Sort key
],
AttributeDefinitions = [
{ 'AttributeName': 'Thermometer', 'AttributeType': 'S' },
{ 'AttributeName': 'GetDate', 'AttributeType': 'N' },
],
ProvisionedThroughput = {
'ReadCapacityUnits': 1,
'WriteCapacityUnits': 1
}
)
print("Table status:", table.table_status)
except Exception as e:
print ("Exception: ", e)
print ("Creating 'Commands' table...")
try:
table = dynamodb.create_table(
TableName = 'Commands',
KeySchema = [
{ 'AttributeName': 'Thermometr', 'KeyType': 'HASH' }, # //Partition key
{ 'AttributeName': 'Boiler', 'KeyType': 'RANGE' } # //Sort key
],
AttributeDefinitions = [
{ 'AttributeName': 'Thermometr', 'AttributeType': 'S' },
{ 'AttributeName': 'Boiler', 'AttributeType': 'S' },
],
ProvisionedThroughput = {
'ReadCapacityUnits': 1,
'WriteCapacityUnits': 1
}
)
print("Table status:", table.table_status)
except Exception as e:
print ("Exception: ",e)