Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
567 views
in Technique[技术] by (71.8m points)

Converting large CSV to JSON in AWS Lambda using python

I have a lambda function which takes an incoming csv file and converts it to JSON. But this is only working on a small file. When I tested with a large file (1GB) it failed with an out of disk space error. I've been searching for ways around this and have read about the boto streaming option. But I'm struggling with how to code for this, since I'm very new to python. Can anyone give me some pointers with this?

Are there any better ways to accomplish my task...converting a large csv to json in lambda using python. Thanks!!

        s3_object = s3.get_object(Bucket=bucket, Key=key)
        data = s3_object['Body'].read()
        contents = data.decode('utf-8')
        
        print(type(filename_csv))
        print(type(key))
        
        with open(filename_csv, 'a') as csv_data:
           csv_data.write(contents)
        
        with open(filename_csv) as csv_data:
            csv_reader = c1.DictReader(csv_data)
            
            with open(filename_json, 'a') as output_file:
                for csv_row in csv_reader:
                    json.dump(csv_row, output_file)
                    output_file.write('
')
            
        with open(filename_json, 'r') as json_file_contents:
            response = s3.put_object(Bucket=bucket, Key=keyname_s3, Body=json_file_contents.read())
question from:https://stackoverflow.com/questions/65894967/converting-large-csv-to-json-in-aws-lambda-using-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...