question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lambda error: Could not unzip uploaded file

See original GitHub issue

I’m trying to update lambda function code

import base64
import boto3
import glob
import os
import zipfile
from StringIO import StringIO

buf = StringIO()
with zipfile.ZipFile(buf, 'w') as z:
    for f in glob.glob(os.path.join(os.path.dirname(__file__), 'app/*.py')):
        z.write(os.path.abspath(f), os.path.basename(f))
buf.seek(0)
pkg = base64.b64encode(buf.read())

client = boto3.client('lambda')
res = client.update_function_code(
    FunctionName='my_function',
    ZipFile=pkg,
    Publish=False
)

Get the ClientError

botocore.exceptions.ClientError: An error occurred (InvalidParameterValueException) when calling the UpdateFunctionCode operation: Could not unzip uploaded file. Please check your file, then try to upload again.

I tried to upload the same package with awscli and it works fine

aws lambda update-function-code --function-name my_function --zip-file=fileb://app.zip

My environment

Python 2.7.9
boto3==1.2.3
botocore==1.3.25

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
jingpengwcommented, Aug 17, 2017

in case this is useful for anyone, this works.

 buf = StringIO()                     
 with zipfile.ZipFile(buf, 'w') as z: 
     z.write(script_name)             
 buf.seek(0)                          
 return buf.read()                    
0reactions
michaeleliotcommented, Jul 25, 2022

I resolved the issue by following this guide. My final code was:

with open('my-deployment-package.zip', 'rb') as f:
	zipped_code = f.read()

client.create_function(
  FunctionName = "FUNCTION_NAME",
  Runtime = "python3.6",
  Code=dict(ZipFile=zipped_code),
  Handler = "FILE.FUNCTION",
  Role = "ROLE"
)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not unzip uploaded file. Please check your file ... - GitHub
I was stuck with this error CREATE_FAILED | AWS::Lambda::LayerVersion | PrismaLayer958161C6 | Could not unzip uploaded file. Please check your file, ...
Read more >
Troubleshoot Lambda deployment package upload errors - AWS
When I try to upload my AWS Lambda deployment package, I get either a permission denied or unable to import module error. How...
Read more >
Node.js – AWS Lambda Error: Could not unzip uploaded file
I am trying to update the code in my lambda function using the aws-sdk package for node.js. So I wrote the following script...
Read more >
Could not unzip uploaded file. Please check your file, then try ...
AWS lambda function through terraform - Could not unzip uploaded file. Please check your file, then try to upload again.
Read more >
Could Not Unzip Uploaded File On Creation Of Lambda ...
AWS Lambda Error: Could not unzip uploaded file. Solution: ZipFile needs to be a Buffer. That means you have to read the file...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found