Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uploaded file must be a non-empty zip #128

Closed
daxAKAhackerman opened this issue Oct 4, 2021 · 6 comments
Closed

Uploaded file must be a non-empty zip #128

daxAKAhackerman opened this issue Oct 4, 2021 · 6 comments
Labels
help wanted Extra attention is needed

Comments

@daxAKAhackerman
Copy link

Hello 👋

I've been trying to use the module for a little while, but I always seem to be hitting a "Uploaded file must be a non-empty zip" error. This happened with my own project, but it also happens with cdk-ecr-deployment-sample.

Reproduction Steps

git clone https://github.com/wchaws/cdk-ecr-deployment-sample.git
cd cdk-ecr-deployment-sample
npm install
npx cdk deploy

What did you expect to happen?

Successful deployment

What actually happened?

12:10:09 PM | CREATE_FAILED        | AWS::Lambda::Function       | CustomCDKECRDeploy...3666512MiB28EAD8E4
Resource handler returned message: "Uploaded file must be a non-empty zip (Service: Lambda, Status Code: 400, Request ID: d2db6a04-6a1e-4094-9047-267cbf632286, Extended Request ID
: null)" (RequestToken: 6eadedf8-538c-e0b8-12ca-74f1859f7dc0, HandlerErrorCode: InvalidRequest)

        new Function (/opt/cdk-ecr-deployment-sample/node_modules/@aws-cdk/aws-lambda/lib/function.ts:377:35)
        \_ SingletonFunction.ensureLambda (/opt/cdk-ecr-deployment-sample/node_modules/@aws-cdk/aws-lambda/lib/singleton-lambda.ts:93:12)
        \_ new SingletonFunction (/opt/cdk-ecr-deployment-sample/node_modules/@aws-cdk/aws-lambda/lib/singleton-lambda.ts:32:32)
        \_ new ECRDeployment (/opt/cdk-ecr-deployment-sample/node_modules/cdk-ecr-deployment/src/index.ts:66:21)
        \_ new CdkEcrDeploymentSampleStack (/opt/cdk-ecr-deployment-sample/lib/cdk-ecr-deployment-sample-stack.ts:21:5)
        \_ Object.<anonymous> (/opt/cdk-ecr-deployment-sample/bin/cdk-ecr-deployment-sample.ts:7:1)
        \_ Module._compile (internal/modules/cjs/loader.js:1072:14)
        \_ Module.m._compile (/opt/cdk-ecr-deployment-sample/node_modules/ts-node/src/index.ts:1056:23)
        \_ Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
        \_ Object.require.extensions.<computed> [as .ts] (/opt/cdk-ecr-deployment-sample/node_modules/ts-node/src/index.ts:1059:12)
        \_ Module.load (internal/modules/cjs/loader.js:937:32)
        \_ Function.Module._load (internal/modules/cjs/loader.js:778:12)
        \_ Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
        \_ main (/opt/cdk-ecr-deployment-sample/node_modules/ts-node/src/bin.ts:198:14)
        \_ Object.<anonymous> (/opt/cdk-ecr-deployment-sample/node_modules/ts-node/src/bin.ts:288:3)
        \_ Module._compile (internal/modules/cjs/loader.js:1072:14)
        \_ Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
        \_ Module.load (internal/modules/cjs/loader.js:937:32)
        \_ Function.Module._load (internal/modules/cjs/loader.js:778:12)
        \_ Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
        \_ /usr/lib/node_modules/npm/node_modules/libnpx/index.js:268:14


 ❌  CdkEcrDeploymentSampleStack failed: Error: The stack named CdkEcrDeploymentSampleStack failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE
    at Object.waitForStackDeploy (/opt/cdk-ecr-deployment-sample/node_modules/aws-cdk/lib/api/util/cloudformation.ts:305:11)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at prepareAndExecuteChangeSet (/opt/cdk-ecr-deployment-sample/node_modules/aws-cdk/lib/api/deploy-stack.ts:342:26)
    at CdkToolkit.deploy (/opt/cdk-ecr-deployment-sample/node_modules/aws-cdk/lib/cdk-toolkit.ts:189:24)
    at initCommandLine (/opt/cdk-ecr-deployment-sample/node_modules/aws-cdk/bin/cdk.ts:225:9)
The stack named CdkEcrDeploymentSampleStack failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE

Environment

  • CDK CLI Version : 1.125.0 (but also tried 1.124.0)
  • Node.js Version : v14.17.6
  • OS : Ubuntu 20.04.3 LTS
  • Language (Version) : TypeScript (3.9.10)

Other

I tried the following:

  • docker system prune --all to start with a fresh docker environment
  • Tried to move around the docker folder
  • Use the path library vs use relative paths for the docker folder
  • Use the 0.0.74 verson of cdk-ecr-deployment
  • Tried deploying multiple times
@wchaws wchaws added the help wanted Extra attention is needed label Oct 4, 2021
@wchaws
Copy link
Contributor

wchaws commented Oct 7, 2021

@daxAKAhackerman Sorry, I can't not reproduce this issue in my gitpod env. Below is my success log.

gitpod /workspace/cdk-ecr-deployment-sample $ npx cdk deploy
This deployment will make potentially sensitive changes according to your current security approval level (--require-approval broadening).
Please confirm you intend to make the following modifications:

IAM Statement Changes
┌───┬───────────────────────────────────────┬────────┬───────────────────────────────────────┬───────────────────────────────────────┬───────────┐
│   │ Resource                              │ Effect │ Action                                │ Principal                             │ Condition │
├───┼───────────────────────────────────────┼────────┼───────────────────────────────────────┼───────────────────────────────────────┼───────────┤
│ + │ ${Custom::CDKECRDeploymentbd07c930edb │ Allow  │ sts:AssumeRole                        │ Service:lambda.amazonaws.com          │           │
│   │ 94112a20f03f096f53666512MiB/ServiceRo │        │                                       │                                       │           │
│   │ le.Arn}                               │        │                                       │                                       │           │
├───┼───────────────────────────────────────┼────────┼───────────────────────────────────────┼───────────────────────────────────────┼───────────┤
│ + │ *                                     │ Allow  │ ecr:BatchCheckLayerAvailability       │ AWS:${Custom::CDKECRDeploymentbd07c93 │           │
│   │                                       │        │ ecr:BatchGetImage                     │ 0edb94112a20f03f096f53666512MiB/Servi │           │
│   │                                       │        │ ecr:CompleteLayerUpload               │ ceRole}                               │           │
│   │                                       │        │ ecr:DescribeImageScanFindings         │                                       │           │
│   │                                       │        │ ecr:DescribeImages                    │                                       │           │
│   │                                       │        │ ecr:DescribeRepositories              │                                       │           │
│   │                                       │        │ ecr:GetAuthorizationToken             │                                       │           │
│   │                                       │        │ ecr:GetDownloadUrlForLayer            │                                       │           │
│   │                                       │        │ ecr:GetRepositoryPolicy               │                                       │           │
│   │                                       │        │ ecr:InitiateLayerUpload               │                                       │           │
│   │                                       │        │ ecr:ListImages                        │                                       │           │
│   │                                       │        │ ecr:ListTagsForResource               │                                       │           │
│   │                                       │        │ ecr:PutImage                          │                                       │           │
│   │                                       │        │ ecr:UploadLayerPart                   │                                       │           │
│ + │ *                                     │ Allow  │ s3:GetObject                          │ AWS:${Custom::CDKECRDeploymentbd07c93 │           │
│   │                                       │        │                                       │ 0edb94112a20f03f096f53666512MiB/Servi │           │
│   │                                       │        │                                       │ ceRole}                               │           │
└───┴───────────────────────────────────────┴────────┴───────────────────────────────────────┴───────────────────────────────────────┴───────────┘
IAM Policy Changes
┌───┬─────────────────────────────────────────────────────────────────────┬──────────────────────────────────────────────────────────────────────┐
│   │ Resource                                                            │ Managed Policy ARN                                                   │
├───┼─────────────────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────┤
│ + │ ${Custom::CDKECRDeploymentbd07c930edb94112a20f03f096f53666512MiB/Se │ arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExe │
│   │ rviceRole}                                                          │ cutionRole                                                           │
└───┴─────────────────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────────┘
(NOTE: There may be security-related changes not in this list. See https://github.com/aws/aws-cdk/issues/1299)

Do you wish to deploy these changes (y/n)? y
CdkEcrDeploymentSampleStack: deploying...
[0%] start: Publishing 2f61dbe9f21c80b34aef4bba11962d5ad49aee0aa2fe8de378b9a730e1b2e534:current
[50%] success: Published 2f61dbe9f21c80b34aef4bba11962d5ad49aee0aa2fe8de378b9a730e1b2e534:current
[50%] start: Publishing d195bc4919540c304d368e3082c0a6103a3661c189ba1b4863162a31ecf4b8e3:current
Sending build context to Docker daemon  2.048kB
Step 1/1 : FROM nginx
latest: Pulling from library/nginx
07aded7c29c6: Pulling fs layer
bbe0b7acc89c: Pulling fs layer
44ac32b0bba8: Pulling fs layer
91d6e3e593db: Pulling fs layer
8700267f2376: Pulling fs layer
4ce73aa6e9b0: Pulling fs layer
8700267f2376: Waiting
4ce73aa6e9b0: Waiting
91d6e3e593db: Waiting
44ac32b0bba8: Verifying Checksum
bbe0b7acc89c: Download complete
07aded7c29c6: Verifying Checksum
07aded7c29c6: Download complete
91d6e3e593db: Download complete
8700267f2376: Verifying Checksum
8700267f2376: Download complete
4ce73aa6e9b0: Verifying Checksum
07aded7c29c6: Pull complete
bbe0b7acc89c: Pull complete
44ac32b0bba8: Pull complete
91d6e3e593db: Pull complete
8700267f2376: Pull complete
4ce73aa6e9b0: Pull complete
Digest: sha256:06e4235e95299b1d6d595c5ef4c41a9b12641f6683136c18394b858967cd1506
Status: Downloaded newer image for nginx:latest
 ---> f8f4ffc8092c
Successfully built f8f4ffc8092c
Successfully tagged cdkasset-d195bc4919540c304d368e3082c0a6103a3661c189ba1b4863162a31ecf4b8e3:latest
The push refers to repository [*******.dkr.ecr.ap-northeast-1.amazonaws.com/aws-cdk/assets]
65e1ea1dc98c: Preparing
88891187bdd7: Preparing
6e109f6c2f99: Preparing
0772cb25d5ca: Preparing
525950111558: Preparing
476baebdfbf7: Preparing
476baebdfbf7: Waiting
6e109f6c2f99: Pushed
0772cb25d5ca: Pushed
88891187bdd7: Pushed
65e1ea1dc98c: Pushed
525950111558: Pushed
476baebdfbf7: Pushed
                        d195bc4919540c304d368e3082c0a6103a3661c189ba1b4863162a31ecf4b8e3: digest: sha256:39065444eb1acb2cfdea6373ca620c921e702b0f447641af5d0e0ea1e48e5e04 size: 1570
[100%] success: Published d195bc4919540c304d368e3082c0a6103a3661c189ba1b4863162a31ecf4b8e3:current
CdkEcrDeploymentSampleStack: creating CloudFormation changeset...
                                                                                                                                                              [[·····[·






 ✅  CdkEcrDeploymentSampleStack

Stack ARN:
arn:aws:cloudformation:ap-northeast-1:*******:stack/CdkEcrDeploymentSampleStack/87e38610-2743-11ec-a567-0a93909845f9
gitpod /workspace/cdk-ecr-deployment-sample $ npx cdk --version
1.125.0 (build 67b4921)

@daxAKAhackerman
Copy link
Author

Just tried it on a fresh install of Ubuntu server, and got the same error.

Just to help me debug, when you tested it in your gitpod env, did you clone the cdk-ecr-deployment-sample from scratch, or were you using a previously cloned version with dependencies already installed? Just trying to see if there could be a version mismatch between your environment and mine that could cause the issue.

Thanks!

@wchaws
Copy link
Contributor

wchaws commented Oct 7, 2021

@daxAKAhackerman I cloned it from scratch.
BTW, I found there's a discussion about this at aws/aws-cdk#12536. Looks like you need to clean all cdktoolkit bucket or rerun bootstrap cdk. Can you retry to test on a different AWS region?

@daxAKAhackerman
Copy link
Author

I tried to cleanup the buckets, cleanup the cdk.out folder, re-bootstrap the region, and even deploy to a new region, but no luck.

It definitely seems to be a problem with the assets upload. In the cdk.out folder, I see that the main file has been created (and is not empty). But in the cdk assets bucket, the created ZIP does not contain the main file.

If you don't think the issue is related to this repo, I will close the issue. However, it's strange that I am not having this issue with other CDK constructs that make use of the CDK assets bucket 🤔

@wchaws
Copy link
Contributor

wchaws commented Oct 7, 2021

@daxAKAhackerman What's your docker version?

@daxAKAhackerman
Copy link
Author

Just tried it on my work computer and it worked, where my NodeJS version is slightly more recent (v14.18.0). Tried to update it on my Ubuntu box and it fixed the issue. So it seems to be a problem with NodeJS v14.17.6 🤷

Closing the issue as it is not related to this repo.

Thank you for your help and for the nice project 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants