How to troubleshoot error “Uploaded file must be a non_empty zip” when updating a Lambda function using AWS CloudFormation ?

2 minute read
Content level: Intermediate
0

This article explains how to troubleshoot the error "Uploaded file must be a non_empty zip” that occurs when attempting to update a Lambda function through AWS CloudFormation stack.

Short Description

This error occurs when attempting to update an AWS Lambda function (AWS::Lambda::Function resource) with a deployment package that is either empty or not in the expected ZIP file format. The update operation requires a non-empty ZIP file containing the function code and dependencies to be provided as the deployment package.

Resolution

Verify the ZIP file is not empty or corrupted:

Linux Terminal:

  • Navigate to the project directory containing your code. In this example, we are assuming the code is saved in a file named lambda_function.py and the directory is named my_function.
cd my_function
  • Check the contents of your zip file:
unzip -l your-lambda-package.zip
  • Ensure proper zip structure: The files should be at the root level of the zip.
  • The following example CLI command create a .zip file named my_deployment_package.zip containing your function code with no dependencies:
zip my_deployment_package.zip lambda_function.py
  • The following commands create a .zip file named my_deployment_package.zip containing your function code and its dependencies (package directory):
zip -r my_deployment_package.zip lambda_function.py package/

Windows Explorer:

  • Make sure you zip the files and subfolders themselves, rather than zipping the parent folder.

  • For example: The zip structure for a Python function might look like below:

my_deployment_package.zip
├── lambda_function.py
├── requirements.txt (if needed)
└── package/ (if you have dependencies)

NOTE: To use the same commands in Windows, you can install the Windows Subsystem for Linux to get a Windows-integrated version of Ubuntu and Bash.


Best Practices

  • Always test the ZIP file locally before deployment.
  • Use AWS SAM for easier Lambda deployments.
  • Consider using Lambda Layers for large dependencies.
  • If you're using a CI/CD pipeline, ensure that the ZIP creation step is working correctly and the artifact is being properly passed to the CloudFormation deployment step. Also, the build process isn't creating an empty ZIP file.

Related information

[+] Creating a .zip deployment package (with or without dependencies) - https://docs.aws.amazon.com/lambda/latest/dg/python-package.html#python-package-create-no-dependencies


Co-Author: Karthik Nujella

profile pictureAWS
SUPPORT ENGINEER
published 2 months ago239 views