-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamodb.py
38 lines (30 loc) · 883 Bytes
/
dynamodb.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
"""
DynamoDB calls in python
"""
import os
import boto
from boto.ec2.regioninfo import RegionInfo
def connect_dynamodb(region):
"""
connect to the right dynamodb
"""
endpoint = "dynamodb.{0}.amazonaws.com".format(region)
region_info = RegionInfo(name=region, endpoint=endpoint)
dDB = boto.connect_dynamodb( os.environ.get('DYNAMODB_ACCESS_KEY'), os.environ.get('DYNAMODB_SECRET_ACCESS_KEY'), region=region_info)
return dDB
def get_table(con, table):
"""
get reference to a specific table
"""
return con.get_table(table)
def get_item(table, item):
"""
get item from specific table
"""
return str(table.get_item(item))
def set_item(table, index, parameters):
"""
add a new index with in a specific table with specific parameters
"""
item = table.new_item( index, attrs=parameters)
item.put()