Skip to content

lambda: corrupt zip archive asset produced when using node v15.6 #12536

@machielg

Description

@machielg

Update from the CDK team

When using local assets with the lambda module using the Code.fromAsset() API, deployment of new assets (during cdk deploy) will fail with the error - "Uploaded file must be a non-empty zip"

We have confirmed this issue manifests when using node engine v15.6. The root cause is being tracked by node - nodejs/node#37027. For the time being, use a node engine < 15.6.

If you have encountered this issue, you need to do three things to resolve this -

  1. Downgrade to a node version < 15.6. You can see what you're current node version is by running node --version.
  2. Delete the cached asset in the cdk.out/ directory. You could safely delete the entire directory, and the correct assets and templates will be re-generated during the next run of cdk synth or cdk deploy.
  3. Delete the previously uploaded asset from the staging bucket. The S3 key of the asset will be prefixed with asset/ and have the hash of the asset. The hash of the asset can be found in your application's CloudFormation template.
    The staging bucket can be obtained by running the following command -
 aws cloudformation describe-stack-resources --stack-name CDKToolkit --logical-resource-id StagingBucket  --query 'StackResources[].PhysicalResourceId'

Original issue filed below

When doing

const fillFn = new lambda.Function(this, "Zip2GzipSQSFill", {
    code: lambda.Code.fromAsset("lib/python"),
    runtime: lambda.Runtime.PYTHON_3_7,
    handler: "mylambda.handler"
    }
);

my file is here (relative to root of the CDK project):
lib/python/mylambda.py

its contents:

def handler(event, context):
    print("HELLO AWS")

I get the error:

Uploaded file must be a non-empty zip (Service: AWSLambdaInternal; Status Code: 400; Error Code: InvalidParameterValueException; Request ID: fcfaf553-70d3-40b8-85d2-a15f6c3bcef0; Proxy: null)

Reproduction Steps

run cdk deploy

What did you expect to happen?

the Lambda is created in AWS

What actually happened?

An zip file is uploaded to the CDK staging bucket, there is a zip file there with my python file, but that file has no contents

Environment

  • CDK CLI Version : 1.85.0 or 1.83.0
  • Framework Version: 1.83.0
  • Node.js Version: 15.6.0
  • OS : MacOS
  • Language (Version): TypeScript (4.1.3)

Other

I'm suspecting it's a nodejs/library problem, in that some library is producing this invalid zip file but I have no evidence of this.


This is 🐛 Bug Report

Metadata

Metadata

Assignees

Labels

@aws-cdk/assetsRelated to the @aws-cdk/assets package@aws-cdk/aws-lambdaRelated to AWS LambdabugThis issue is a bug.p0

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions