[cli] cdk deploy with --app flag not correctly uploading zip files
See original GitHub issueWhen using cdk deploy
with an app reference (e.g. with the --app
flag pointing to the directory where the CDK synth output artifacts are located) does not zip and upload assets correctly, resulting in a Lambda error:
Uploaded file must be a non-empty zip (Service: AWSLambdaInternal; Status Code: 400; Error Code: InvalidParameterValueException)
Running cdk deploy
from the base CDK package directory (the immediate parent of the ./build folder where I previously ran cdk deploy --app) results in no issues whatsoever.
Reproduction Steps
- Create a new CDK package:
cdk init --langauge typescript app
In the main stack file, I simply use this stack:
import * as cdk from '@aws-cdk/core';
import * as r53 from '@aws-cdk/aws-route53';
import * as cert from '@aws-cdk/aws-certificatemanager';
export class CdkBugReproStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new cert.DnsValidatedCertificate(this, 'Certificate', {
hostedZone: new r53.HostedZone(this, 'Zone', {
zoneName: 'my-cdk-bug-repro.com'
}),
domainName: 'my-cdk-bug-repro.com'
});
}
}
In the bin/infrastructure.ts file, I give an account ID and a region. Then I synthesize, bootstrap, and deploy.
cdk synth -o ./build CdkBugReproStack
cdk bootstrap aws://123456789/eu-west-1
cd ./build
cdk deploy --app ./ CdkBugReproStack
This used to work (during work hours I can check what CDK versions it worked with), so it seems to be a regression of some sorts. The asset that is allegedly empty is not empty in the ./build subdirectory - it consists of a directory with the assetId as the name, and a single file “index.js” for the DnsValidatedCertificate custom resource Lambda. When I check the staging directory however, the zip file created is only 22 bytes and has no content inside of it.
What did you expect to happen?
Running cdk deploy should work with the --app flag from the build directory the same way it does from the root CDK directory without the --app flag.
The use case of passing the --app flag is to use CodeBuild to create the build artifacts in the build stage of my pipeline, and not re-synthesize before deployment (potentially deploying code that wasn’t tested in the build step.
What actually happened?
The CDK deployment failed when using the --app flag, with CloudFormation/Lambda correctly showing that the .zip file in the CDK staging bucket is empty.
5/10 \| 1:04:01 AM \| CREATE_FAILED \| AWS::Lambda::Function \| WebsiteCert/CertificateRequestorFunction (WebsiteCertCertificateRequestorFunction6B9B1618) Uploaded file must be a non-empty zip (Service: AWSLambdaInternal; Status Code: 400; Error Code: InvalidParameterValueException; Request ID: a8efe092-d154-4c3f-bce7-89350822ada6; Proxy: null)
--
70 | new Function (/codebuild/output/src458118030/src/packages/infrastructure/node_modules/@aws-cdk/aws-lambda/lib/function.ts:592:35)
71 | \_ new DnsValidatedCertificate (/codebuild/output/src458118030/src/packages/infrastructure/node_modules/@aws-cdk/aws-certificatemanager/lib/dns-validated-certificate.ts:76:31)
72 | \_ new CoreStack (/codebuild/output/src458118030/src/packages/infrastructure/lib/core/core-stack.ts:22:25)
73 | \_ /codebuild/output/src458118030/src/packages/infrastructure/bin/infrastructure.ts:17:3
74 | \_ Array.forEach (<anonymous>)
Environment
- CLI Version 1.60.0 (build 8e3f53a) :
- Framework Version: 1.61.1
- Node.js Version: v14.9.0
- OS : OSX
- Language (Version): TypeScript (3.9.6)
Other
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
@rix0rrr — I am also experiencing the same issue after upgrading to CDK version
1.85.0
from1.73.0
that is working fine.@rix0rrr I am experiencing the same issue with 1.84.0. The
index.js
insidecdk.out/asset...
looks normal. However, insidecdk.out/.cache/...zip
theindex.js
is zero bytes long.