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.

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

Most upvoted comments

I also get this error message when I run cdk deploy then cancel it using CTRL + C during 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 .gitignore I 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:

  const senderLambda = new lambda.Function(params.scope, params.functionName, {
    runtime: lambda.Runtime.NODEJS_14_X,
    handler: 'sender.handler',
    code: lambda.Code.fromAsset(path.join(__dirname, 'email-sender-lambda')),
    functionName: params.functionName,
    environment: {
      EMAIL_FROM: params.emailFrom,
      EMAIL_TO: params.emailTo,
      EMAIL_BCC: params.emailBcc
    }
  });

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:

  • for another project I added other wsl distribution and set it as default
  • docker switched itself to “Resource saving mode” which caused cdk synth to run extremely slowly
  • I cancelled cdk deploy (due to being slow) using Ctrl+C

Steps to fix my issue:

  1. revert wsl default distro to docker-desktop: wsl --set-default docker-desktop
  2. in Docker Desktop disable Resource Saver mode in Settings -> Resources
  3. restart Docker Desktop
  4. delete cdk.out
  5. run cdk synth

Note: Possibly, a subset of the five steps listed above might be sufficient to resolve the issue.

Has this issue been really closed? I am getting the following error in the Assets step my of code pipeline. The same code works fine when I deploy locally via cdk deploy

error  : [0%] fail: 🚨 WARNING: EMPTY ZIP FILE 🚨
--
43 | error  : [0%] fail:
44 | error  : [0%] fail: Zipping this asset produced an empty zip file. We do not know the root cause for this yet, and we need your help tracking it down.

dockerEnabledForSynth: true is set for the pipeline The build project runs on aws/codebuild/standard:5.0

Yeah I’m definitely still seeing this issue in development. Totally get it’s a really tough one to solve, but it might need to be re-opened sadly.

@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:

@LeeMartin77 https://github.com/LeeMartin77 & @thovden https://github.com/thovden was it persistant until you deleted the cdk.out dir? It’s always been a once off when I’ve had it, (deploy again without changing anything will pass).

Wonder if deleting that dir will reduce the amount it happens.

— Reply to this email directly, view it on GitHub https://github.com/aws/aws-cdk/issues/18459#issuecomment-1146969450, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJUVAAFVRUVQSSX3QRIQQLVNVOQBANCNFSM5MB7RRGQ . You are receiving this because you were mentioned.Message ID: @.***>

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.out directory

Annecdotally, 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 where cdk.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 cancelling cdk deploy at the wrong time.

I was able to resolve my error by deleting the empty ZIP file from S3 and deleting cdk.out

OS: 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.PythonFunction construct.

It didn’t happen again after deleting the cdk.out directory and re-synthesizing.


OS: macOS Monterery v12.2.1 Node: v16.14.2 CDK: 2.10.0 (build e5b301f) Package Manager: pip