AWS CDK S3 Deployment Error - Uploaded file must be a non-empty zip

Viewed 1896

I am trying to upload a static webpage onto s3 utilizing the AWS CDK with the S3 and S3 Deployment modules. The issue is that the deployment goes well until I get an error that states that the uploaded file must be a non-empty zip. the documentation indicates that I should be able to use a directory, but I've tried it with a zip as well and the same error persists. Not sure how to proceed.

enter image description here

import * as CDK from "@aws-cdk/core";
import * as S3 from "@aws-cdk/aws-s3";
import * as S3Deployment from "@aws-cdk/aws-s3-deployment";

const path = "../website.zip";

export class WebsiteStack extends CDK.Stack {
     constructor(app: CDK.App, id: string, props?: CDK.StackProps) {
      super(app, id, props);

const bucket = new S3.Bucket(this, "Files", {
  websiteIndexDocument: "index.html",
  publicReadAccess: true,
});

new S3Deployment.BucketDeployment(this, "Deployment", {
  sources: [S3Deployment.Source.asset(path)],
  destinationBucket: bucket,
  
});

new CDK.CfnOutput(this, "BucketDomain", {
  value: bucket.bucketWebsiteDomainName,
});

} }

1 Answers

If you are doing this in early 2021, check what version of NodeJS you are using. If it's 15.6 to 15.8, a bug was introduced that broke the way .zip files are built which causes this error.

The CDK bug is #12536 and the upstream NodeJS bug is #37027.

Reverting back to 15.5 or earlier should fix the problem, and it looks like NodeJS 15.9 may have fixed the issue too but I haven't confirmed this.

Related