aws-cdk: (aws-lambda-nodejs): Uploaded file must be a non-empty zip
What is the problem?
I updated lambda function dependancies and deploying the lambda function but it fails with following error.

I also have another api under the same project and I updated its lambda function dependancies and it was deployed successfully.
Both api’s and its lambda functions are almost identical to each other. However only one gets deployed and another one doesn’t.
I deleted the cdk.out folder and tried to deploy again and it fails with same error each time.
Reproduction Steps
I have simple lambda function that I am trying to deploy as follows
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
import { Architecture, Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda';
const authFn = new NodejsFunction(this, 'authNodeJs', {
runtime: Runtime.NODEJS_14_X,
entry: `${__dirname}/../auth/index.ts`,
handler: 'auth',
architecture: Architecture.ARM_64,
memorySize: 1024,
environment: {
CLIENT_ID: appClientID
}
})
const auth1Fn = new Function(this, 'authGolang', {
runtime: Runtime.GO_1_X,
code: Code.fromAsset(`${__dirname}/../auth-1/`, {
bundling: {
image: Runtime.GO_1_X.bundlingImage,
user: 'root',
command: [
'bash', '-c', [
'cd /asset-input',
'go build -o main main.go',
'mv /asset-input/main /asset-output/'
].join(' && ')
]
}
}),
handler: 'main',
memorySize: 512,
environment: {
CLIENT_ID: appClientID
}
})
What did you expect to happen?
I expected it to deploy all of my lambda functions.
What actually happened?
It failed with error Uploaded file must be a non-empty zip
CDK CLI Version
2.8.0
Framework Version
No response
Node.js Version
v16.13.2
OS
Ubuntu 20.04 on WSL 2
Language
Typescript
Language Version
~3.9.7
Other information
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 17
- Comments: 55 (4 by maintainers)
Commits related to this issue
- chore: prevent empty zip uploads Due to something we haven't completely figured out yet, our asset packaging sometimes produces empty zip files, leading to an error like this uploading code Lambda: ... — committed to aws/aws-cdk by rix0rrr 2 years ago
- chore: prevent empty zip uploads (#18487) Due to something we haven't completely figured out yet, our asset packaging sometimes produces empty zip files, leading to an error like this uploading code ... — committed to aws/aws-cdk by rix0rrr 2 years ago
- chore: prevent empty zip uploads (#18487) Due to something we haven't completely figured out yet, our asset packaging sometimes produces empty zip files, leading to an error like this uploading code ... — committed to TikiTDO/aws-cdk by rix0rrr 2 years ago
- fix: half-written asset zips can be uploaded if process is interrupted Here's a possible scenario that can lead to "Uploaded file must be a non-empty zip": - Bundling starts - A partial zip file is ... — committed to aws/aws-cdk by rix0rrr 2 years ago
- fix: half-written asset zips can be uploaded if process is interrupted (#22393) Here's a possible scenario that can lead to "Uploaded file must be a non-empty zip": - Bundling starts - A partial zip... — committed to aws/aws-cdk by rix0rrr 2 years ago
- fix: half-written asset zips can be uploaded if process is interrupted (#22393) Here's a possible scenario that can lead to "Uploaded file must be a non-empty zip": - Bundling starts - A partial zip... — committed to arewa/aws-cdk by rix0rrr 2 years ago
- fix: half-written asset zips can be uploaded if process is interrupted (#22393) Here's a possible scenario that can lead to "Uploaded file must be a non-empty zip": - Bundling starts - A partial zip... — committed to homakk/aws-cdk by rix0rrr 2 years ago
I also get this error message when I run
cdk deploythen cancel it usingCTRL + Cduring the bundling stage.When I try to redeploy, it appears to bundle everything again but during the CloudFormation deployment, this error message is shown and fails to deploy.
If I redeploy again, it bundles everything up and then deploys successfully.
It appears as though the second bundling attempt isn’t successful?
Got this error message when upgrading aws-cdk-lib version from 2.31.0 to 2.32.0.
Looks like for some (unknown) reason an empty zip file landed on S3 for this asset.
It should be fixed If you manually remove the asset file from the bootstrap bucket and then retry.
In my case it was a human error. I had a CDK project with TypeScript where I had a lambda written in JavaScript. In
.gitignoreI had an entry that simply excluded javascript files. Once I checked out the repository on another computer the JavaScript file with the lambda was obviously not there. Took me at least two hours to realise that.This is my typescript code:
The lambda was meant to be in
email-sender-lambda/sender.js.Guess it would be good to have a different error/warning message there or simply fail the deployment as soon as the file cannot be found during compilation.
I was getting the same error and I managed to solve it for my particular case.
Stack: Windows 10 wsl2 Docker Desktop
Events (possibly) leading to my issue:
Steps to fix my issue:
wsl --set-default docker-desktopNote: Possibly, a subset of the five steps listed above might be sufficient to resolve the issue.
@abury Just got mine fixed. I had to update the CDK CLI version to 2.46.0 (or newer).
For me it was persistent before deleting the cdk.out folder.
On Mon, Jun 6, 2022, 04:25 Aron @.***> wrote:
I had this today, on a pretty small project:
OS version: Debian GNU/Linux 11 Nodejs version: 16.15.1 CLI version: 2.26.0 (build a409d63) package manager: npm what the asset is supposed to contain: Compiled JS from source Typescript files reproducable: Went away after I deleted my
cdk.outdirectoryAnnecdotally, I’ve been doing a lot of deploys, and had quite a lot of asset folders by the time this happened.
My issue was resolved… somehow on the initial deploy, Docker didn’t have access to the node_modules in Lambda and empty assets were uploaded. I deleted the cdk.out folder locally, tore down the stacks and the pipeline, re-uploaded, and was good to go.
I had this issue occurring from
aws_lambda_python_alpha.PythonFunction. Somehow I had got into a state wherecdk.out/asset.{hash}/folder had the correct files, but there was a corresponding ZIP file uploaded to the CDK S3 artifacts bucket which was empty. It’s possible this empty zip was uploaded due to me cancellingcdk deployat the wrong time.I was able to resolve my error by deleting the empty ZIP file from S3 and deleting
cdk.outOS: Ubuntu 20.04.4 LTS Node: v14.18.3 CDK: 2.8.0 (build 8a5eb49) Package Manager: pip
This just happened with us as well using the
aws_lambda_python_alpha.PythonFunctionconstruct.It didn’t happen again after deleting the
cdk.outdirectory and re-synthesizing.OS: macOS Monterery v12.2.1 Node: v16.14.2 CDK: 2.10.0 (build e5b301f) Package Manager: pip