I am using NOSql dynamodb for my Project. I want an auto generated key which i can use for queries. I have looked into many forums but havent got any answer for python. Kindly help me generating auto key. thanks
DynamoDB_view(tableName, campaign_tag_app_group_map_id, campaign_id,
tag_id, tag_type, app_id, group_id, group_p, tenant_id,
insertion_timestamp, insertion_user_id):
print "in func DynamoDB_view"
def insert_to_dynamo(conn, tableName, campaign_tag_app_group_map_id, campaign_id,
tag_id, tag_type, app_id, group_id, group_p, tenant_id,
insertion_timestamp, insertion_user_id):
print "in Insert"
print tableName
# uswd the data as random key generation just for now. this is inappropriate
data = str(uuid.uuid4().get_hex()[0:16])
table = conn.get_table(tableName)
item_data = {
'campaign_id': str(campaign_id),
'tag_id': tag_id,
'tag_type': tag_type,
'app_id' : app_id,
'group_id' : str(group_id),
'group_p' : group_p,
'tenant_id' : str(tenant_id),
'insertion_timestamp' : str(datetime.now()),
'insertion_user_id' : str(insertion_user_id)
}
item = table.new_item(
# Our hash key is 'forum'
hash_key=data,
range_key='Check this out!',
attrs=item_data
)
item.put()
def connection_dynamo(tableName, campaign_tag_app_group_map_id, campaign_id,
tag_id, tag_type, app_id, group_id, group_p, tenant_id,
insertion_timestamp, insertion_user_id):
conn = boto.dynamodb.connect_to_region(
'us-east-1',
aws_access_key_id=settings.ACCESS_KEY,
aws_secret_access_key=settings.PASS_KEY)
insert_to_dynamo(conn,tableName, campaign_tag_app_group_map_id, campaign_id,
tag_id, tag_type, app_id, group_id, group_p, tenant_id,
insertion_timestamp, insertion_user_id)
connection_dynamo(tableName, campaign_tag_app_group_map_id, campaign_id,
tag_id, tag_type, app_id, group_id, group_p, tenant_id,
insertion_timestamp, insertion_user_id)
Aucun commentaire:
Enregistrer un commentaire