question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[cli] cdk deploy with --app flag not correctly uploading zip files

See original GitHub issue

When 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

  1. 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:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
RigoMirandacommented, Jan 18, 2021

@rix0rrr — I am also experiencing the same issue after upgrading to CDK version 1.85.0 from 1.73.0 that is working fine.

4reactions
danilobuergercommented, Jan 17, 2021

@rix0rrr I am experiencing the same issue with 1.84.0. The index.js inside cdk.out/asset... looks normal. However, inside cdk.out/.cache/...zip the index.js is zero bytes long.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting common AWS CDK issues
This topic describes how to troubleshoot the following issues with the AWS CDK. After updating the AWS CDK, the AWS CDK Toolkit (CLI)...
Read more >
aws-cdk.pipelines
CDK Pipelines is an opinionated construct library. It is purpose-built to deploy one or more copies of your CDK applications using CloudFormation with...
Read more >
Lambda can't find modules from outer folders when ...
Problem was CDK not deploying the node_modules folder and other folders which are outside the folder which contains the lambda source file.
Read more >
@aws-cdk/aws-s3-deployment | Yarn - Package Manager
This library allows populating an S3 bucket with the contents of .zip files from other S3 buckets or from local disk. The following...
Read more >
awslabs/aws-cdk - Gitter
So far I've only been able to create an Amplify deployment using the CLI and providing an OAuth token. I've not been able...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found