File tree 3 files changed +66
-0
lines changed
3 files changed +66
-0
lines changed Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments