def eventHandler(event, context): """ Main lambda for our classification. It invokes lambda enrich location as a first step. Case RAW : only add lcoation and google place type if finded Case Structured : send Purchease classification, our classif is only used if Purchease send Non-Reconnu :param event: json input send by Purchease :param context: non need :return: output json to be send to Purchease """ print "event init :", event d = AccessDB(event['stageVariables']) event_bytes = json.dumps(event['body']) function_name = event['stageVariables'][ 'stage'] + '-' + "smartticket-location" invoke_response = lambda_client.invoke(FunctionName=function_name, InvocationType='RequestResponse', Payload=event_bytes) new_event = invoke_response['Payload'].read() print "New event : ", new_event new_event_smartt = json.loads(new_event)['smartticket'] new_event_smartt = replace_empty_string(new_event_smartt) if new_event_smartt['extraction_type'] == 'STRUCTURED': ll = LoadPurchease(new_event_smartt) output_full = ll.fill_input_with_classif(new_event_smartt) # Save into db d.put_item_into_dynamodb(output_full) # Clean output for send into post : del purchease_cat and rmw_cat, only stay cat return respond('', ll.good_shape_output_for_post(output_full)) else: return respond('', new_event)
def eventHandler(event, context): print "event init :", event d = AccessDB(event['stageVariables']) event_bytes = json.dumps(event['body']) function_name = event['stageVariables'][ 'stage'] + '-' + "smartticket-location" invoke_response = lambda_client.invoke(FunctionName=function_name, InvocationType='RequestResponse', Payload=event_bytes) new_event = invoke_response['Payload'].read() print "New event : ", new_event new_event_smartt = json.loads(new_event)['smartticket'] new_event_smartt = replace_empty_string(new_event_smartt) if new_event_smartt['extraction_type'] == 'STRUCTURED': ll = LoadPurchease(new_event_smartt) output_full = ll.fill_input_with_classif(new_event_smartt) # Save into db d.put_item_into_dynamodb(output_full) # Clean output for send into post : del purchease_cat and rmw_cat, only stay cat return respond('', ll.good_shape_output_for_post(output_full)) else: return respond('', new_event)
import cPickle as pickle from time import gmtime, strftime import boto3 import pandas as pd import re import sklearn.metrics as m from sklearn.model_selection import cross_val_score from utilCsv import UnicodeWriter, Utils from Code.Utils.utilNormalizer import Normalizer from Code.db_access.dynamoDB import AccessDB from tfidfClassification import Classification # TODO : create context a = AccessDB() c = Classification() n = Normalizer() u = Utils() # AWS Access client = boto3.client('s3', region_name="eu-west-1") s3 = boto3.resource('s3') tfidfp = client.get_object(Bucket='smartticket-analytics', Key='dumpTfIdf.pkl') tf_idf_load_from_pickle = pickle.loads(tfidfp['Body'].read()) rfp = client.get_object(Bucket='smartticket-analytics', Key='dumpRf.pkl') rf_load_from_pickle = pickle.loads(rfp['Body'].read()) table = boto3.resource('dynamodb').Table('prod-analytics-smarttickets') classif_result = s3.Object(bucket_name='smartticket-analytics', key='classif_results.csv')
from Code.db_access.accessRds import AccessRDS from Code.db_access.dynamoDB import AccessDB from Code.db_access.dynamoDBDataPrep import dynamoDBPrep ards = AccessRDS() ad = AccessDB() d = dynamoDBPrep() def handler(event, context): # Get dynamobd data : full info TODO replace by active flow input_json = ad.get_item_from_dynamodb() result_df = d.from_dynamo_to_mysql(input_json) ards.getBonsPlansInfosRow(result_df) handler('', '')