Assets: Zip archive is corrupted for Lambda code
See original GitHub issueReproduction Steps
I have a regular Lambda stack that looks something like:
const lambdaDeleteDDBFn = new Function(this, 'LambdaToDeleteDDB', {
runtime: Runtime.NODEJS_10_X,
handler: 'delete-ddb-table-lambda.handle',
// The path should be relative to the root directory.
code: Code.asset('./lib/lambda'),
timeout: Duration.seconds(300),
environment: {
REGION: this.region,
TABLE_NAME: tableName
}
});
The ./lib/lambda
directory looks normal as well which includes already compiled JS files:
$ ll lib/lambda/
total 64
-rw-r--r-- 1 user 1896053708 5324 3 Jan 09:17 create-invalid-stack-lambda.js
-rw-r--r-- 1 user 1896053708 4719 3 Jan 09:17 custom-resource-utils.js
-rw-r--r-- 1 user 1896053708 3501 3 Jan 09:17 delete-ddb-table-lambda.js
-rw-r--r-- 1 user 1896053708 1148 2 Jan 15:25 custom-resource-utils.ts
-rw-r--r-- 1 user 1896053708 870 2 Jan 15:18 delete-ddb-table-lambda.ts
-rw-r--r-- 1 user 1896053708 1401 2 Jan 14:10 create-invalid-stack-lambda.ts
Once CDK app is build, it generates cdk.out
with bunch of template JSON files as well as the asset.XXX
directory that is a copy of the ./lib/lambda
directory.
$ ll build/cdk.out/asset.12efd52ab96c4083197e09d00af8f35f6f4f02b951217130bede554ac178685b
total 64
-rw-r--r-- 1 user 1896053708 5324 3 Jan 09:18 create-invalid-stack-lambda.js
-rw-r--r-- 1 user 1896053708 1401 3 Jan 09:18 create-invalid-stack-lambda.ts
-rw-r--r-- 1 user 1896053708 4719 3 Jan 09:18 custom-resource-utils.js
-rw-r--r-- 1 user 1896053708 1148 3 Jan 09:18 custom-resource-utils.ts
-rw-r--r-- 1 user 1896053708 3501 3 Jan 09:18 delete-ddb-table-lambda.js
-rw-r--r-- 1 user 1896053708 870 3 Jan 09:18 delete-ddb-table-lambda.ts
We can confirm that bytes sizes of files match the original files.
Error Log
Then this directory gets zipped by CDK by the zipDirectory()
function which, however, generates a corrupted ZIP file. I think the underlying archiver
NPM module has a bug somewhere.
$ unzip -t build/cdk.out/asset.12efd52ab96c4083197e09d00af8f35f6f4f02b951217130bede554ac178685b.zip
Archive: build/cdk.out/asset.12efd52ab96c4083197e09d00af8f35f6f4f02b951217130bede554ac178685b.zip
testing: create-invalid-stack-lambda.js bad CRC 28acfbde (should be 6bd7e1c9)
file #2: bad zipfile offset (local header sig): 2731
file #3: bad zipfile offset (local header sig): 5009
file #4: bad zipfile offset (local header sig): 5771
testing: delete-ddb-table-lambda.js OK
testing: delete-ddb-table-lambda.ts OK
At least one error was detected in build/cdk.out/asset.12efd52ab96c4083197e09d00af8f35f6f4f02b951217130bede554ac178685b.zip.
When I try to force unzip locally, the following error is displayed:
Unable to expand "asset.12efd52ab96c4083197e09d00af8f35f6f4f02b951217130bede554ac178685b.zip` into "cdk.out".
The deployment to the actual stack also fails with the following error:
Could not unzip uploaded file. Please check your file, then try to upload again. (Service: AWSLambdaInternal; Status Code: 400; Error Code: InvalidParameterValueException; Request ID: 853d7206-2f80-422e-a7ff-01c15b960ed9)
When I check the file size, I see the following:
$ ll build/cdk.out/
-rw-r--r-- 1 user 1896053708 10218 3 Jan 09:53 asset.12efd52ab96c4083197e09d00af8f35f6f4f02b951217130bede554ac178685b - CORRECT.zip
-rw-r--r--@ 1 user 1896053708 9280 3 Jan 09:18 asset.12efd52ab96c4083197e09d00af8f35f6f4f02b951217130bede554ac178685b.zip
Note that the file size of the correct zip which I manually generated is 10KB while the actual one generated by CDK is 9KB.
Environment
- CLI Version : 1.17.1
- Framework Version: 1.17.1
- OS : macOS Mojave
- Language : TypeScript
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (3 by maintainers)
Top GitHub Comments
With CDK 1.67, all of a sudden I got the same error when deploying from my command line to my cloud env:
Could not unzip uploaded file. Please check your file, then try to upload again. (Service: AWSLambdaInternal; Status Code: 400; Error Code: Inval
Even going back to master branch, to code that is currently deployed, I would get the same error. I just cleaned my CDKtoolkit assets folder in S3 and then I could deploy again. Then I went back to my new branch and was able to deploy too. So weird.I’m getting the same issue here as well. @eladb the zip files in the
cdk.out
folder are just the asset.* files for me.The error that I get from running
cdk deploy MyStack
isThe error I get then I try to run
unzip cdk.out/asset.0ea27e9d503ee9ddf6c3eb85001baf39528958392bb3ebef1ec069c68450c946.zip
isI’m on
aws-cdk: 1.45.0
and a Macbook Pro10.15.4