Hi Dears,
Hope all is good
I have lambda function written in python (event driven ETL), I use two packaged functions to handel one csv file. I want to use the input csv file (S3 object uploaded to the bucket) in the two functions and put two json files in two different s3 buckets as an output.
But When I used the code as below, It convert the first function(df_out_1) successfully but in second function (df_out_2) give me error message that " No columns to parse from file
" for the second function :
The code as below:
def lambda_handler(event, context):
s3_client = boto3.client('s3')
s3 = boto3.resource('s3')
if event:
try:
obj = event['Records'][0]
bucket_name = obj['s3']['bucket']['name']
file = obj['s3']['object']['key']
csv_object = s3_client.get_object(Bucket = bucket_name , Key = file)
csv_content = csv_object['Body'].read()
bite = io.BytesIO(csv_content)
df_out_1 = csv_json_function_alex_dep(bite)
s3.Object('midibus-sagemaker-ai-engine-2' , jsonkey ).put(Body=json.dumps(df_out_1))
print('The file is converted successfully for model-1 input!')
#change input later to be jsonkey
df_out_2 = csv_json_function_alex_arri(bite)
s3.Object('midibus-sagemaker-ai-engine-2', jsonkey ).put(Body=json.dumps(df_out_2))
print('The file is converted successfully for model-2 input!')
return {
'statusCode': 200,
'body': json.dumps('The file is converted successfully!')
}
except BaseException as err:
print("Oops! Something went wrong ! \\n")
print(err)
print(err.args)
traceback.print_exc(limit=5)
return {
'statusCode': 400,
'body': json.dumps('Something went wrong!')
}
thanks,
Basem
Thanks!! It works well, Why we put it again with the second function?