serverless / serverless/examples
My lambda function is unable to unzip a file
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 11.5k
- Forks
- 4.4k
- Avg merge
- 2h 55m
- Merged PRs (30d)
- 3
Description
I deployed a flask app to lambda that includes a function that unzip a small file (124ko), but nothing works as expected. The unzipping clearly fail and I can't find the reason.
2021-03-23T12:12:46.346+01:00 error [/tmp/39423ff39f7f4378a8f835a20fdcb688.zip]: missing 3183398882 bytes in zipfile
2021-03-23T12:12:46.346+01:00 (attempting to process anyway)
2021-03-23T12:12:46.346+01:00 error [/tmp/39423ff39f7f4378a8f835a20fdcb688.zip]: start of central directory not found;
2021-03-23T12:12:46.346+01:00 zipfile corrupt.
2021-03-23T12:12:46.346+01:00 (please check that you have transferred or created the zipfile in the
2021-03-23T12:12:46.346+01:00 appropriate BINARY mode and that you have compiled UnZip properly)
There is no problem when testing locally and the zip file is okay. So I guess the issue comes from lambda.
The code :
with open(file_path, "wb") as binary_file:
binary_file.write(file_content)
Expected behavior : The file should unzip without problem just as it does when the app runs locally or in heroku.
P.S. I am using postman for testing
EDIT : also tried to extract with zipfile
with zipfile.ZipFile('/tmp/myfile.zip', 'r') as z:
z.extractall(fil_dir)
and got the following error :
raise BadZipFile("Bad magic number for central directory")
Originally I was extracting with
os.system("unzip -qq %s -d %s" % (file_path,file_dir))
Any suggestion ?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Lambda function that writes file_content to /tmp/file_path and compare the bytes received through Postman with the local or Heroku input. Verify the saved archive with the shown zipfile.ZipFile call before extraction; done means the same archive opens and extracts successfully in Lambda.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, flask, python
- Domain
- backend, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100