Python 从 MYSQL 下载转储文件时 S3 和 Lambda 出现只读文件系统错误

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

我有以下代码用于 运行 来自 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

我在尝试从 lambda 执行此操作时遇到以下错误。 我对文件夹和 csv 文件授予了完全权限

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

我相信在 Lambda 上,您只能按照记录 here/tmp 目录中写入文件。 尝试调整您的代码来做到这一点,它应该可以工作。