【以下的问题经过翻译处理】 我有一个用Python编写的Lambda函数(事件驱动的ETL),我使用两个封装的函数来处理一个CSV文件。我想在这两个函数中使用输入的CSV文件(上传到存储桶的S3对象),并将两个JSON文件作为输出放入两个不同的S3存储桶中。
但是,当我使用下面的代码时,它成功地转换了第一个函数(df_out_1),但在第二个函数(df_out_2)中给我一个错误消息,"No columns to parse from file":
代码如下:
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!')
}