Skip to content

Commit c0110c5

Browse files
author
Alexey Gadzhiev
committed
initial commit
0 parents  commit c0110c5

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

create_table.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from __future__ import print_function # Python 2/3 compatibility
2+
import boto3
3+
4+
dynamodb = boto3.resource('dynamodb', region_name='us-west-2', endpoint_url="http://localhost:8000")
5+
6+
7+
table = dynamodb.create_table(
8+
TableName = 'Temperature',
9+
KeySchema = [
10+
{ 'AttributeName': 'Thermometer', 'KeyType': 'HASH' }, # //Partition key
11+
{ 'AttributeName': 'GetDate', 'KeyType': 'RANGE' } #//Sort key
12+
],
13+
AttributeDefinitions = [
14+
{ 'AttributeName': 'Thermometer', 'AttributeType': 'S' },
15+
{ 'AttributeName': 'GetDate', 'AttributeType': 'N' },
16+
],
17+
ProvisionedThroughput = {
18+
'ReadCapacityUnits': 10,
19+
'WriteCapacityUnits': 10
20+
}
21+
)
22+
23+
print("Table status:", table.table_status)

put_item.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from __future__ import print_function # Python 2/3 compatibility
2+
import boto3
3+
import decimal
4+
import time
5+
6+
7+
def get_val(thermo):
8+
return decimal.Decimal('25.3')
9+
10+
def get_now():
11+
return decimal.Decimal(time.time())
12+
13+
14+
dynamodb = boto3.resource('dynamodb', region_name='us-west-2', endpoint_url="http://localhost:8000")
15+
16+
table = dynamodb.Table('Temperature');
17+
thermo_name="InsideHall";
18+
19+
for f in range(2):
20+
response=table.put_item(
21+
Item={
22+
'Thermometer': thermo_name,
23+
'GetDate': get_now(),
24+
'val': get_val(thermo_name),
25+
}
26+
)
27+
print('put_item result:', response)

table.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
TableName : "Tempreture",
3+
KeySchema: [
4+
{ AttributeName: "Termometr", KeyType: "HASH" }, //Partition key
5+
{ AttributeName: "GetDate", KeyType: "RANGE" } //Sort key
6+
],
7+
AttributeDefinitions: [
8+
{ AttributeName: "Termometr", AttributeType: "S" },
9+
{ AttributeName: "GetDate", AttributeType: "S" },
10+
{ AttributeName: 'Val', AttributeType: "N" }
11+
],
12+
ProvisionedThroughput: {
13+
ReadCapacityUnits: 10,
14+
WriteCapacityUnits: 10
15+
}
16+
};

0 commit comments

Comments
 (0)