padmaja cherukuri
padmaja cherukuri

Reputation: 413

Python Read-only file system Error With S3 and Lambda when downloading a dump file from MYSQL

I'have the following code for running query from mysql

        dump_query=/media/+"/mysql -u"+user+" -p'"+passwd+"' -h"+host+" "+name+" -e '"+query+"' | sed 's/\t/,/g' > "+filepath+"test.csv"
 proc = subprocess.Popen(dump_query, shell=True)
        proc.wait()
        fs = FileSystemStorage(filepath)            
        with fs.open('test.csv') as record:
            if os.path.getsize(str(record)) == 0:
                messages.warning(request,"No Data available to download")
                if nexturl is not None:
                    return redirect(nexturl)
                else:
                    return redirect('admin_reports:status_index')
            response = HttpResponse(record, content_type='application/csv')
            response['Content-Disposition'] = 'filename="'+filename+'.csv"'             
            return response

I'm getting the below error while i'm trying to do this from lambda. I gave full permisisons to the folder and csv file

 /bin/sh: /var/task/media/downloads/test.csv: Read-only file system

Upvotes: 0

Views: 338

Answers (1)

Ghonima
Ghonima

Reputation: 3092

I believe on the Lambda, you can only write files on the /tmp directory as documented here. Try adjusting your code to do that and it should work.

Upvotes: 1

Related Questions