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.

Errors using ZipFile in the BucketDeployment Construct

See original GitHub issue

šŸ› Bug Report

We use the BucketDeployment construct to perform deployments of our static assets for a website that is then distributed using CloudFront.

While using this, we have received a couple of different transient errors that would block deployments. These errors have either been one of the following (with ABC and XYZ being file names we are trying to deploy).

  • File name in directory ABC and header XYZ differ
  • Bad CRC-32 for file ACB

Once these occurred, retrying the same deployment didnā€™t ever work and the only thing that has seemed to fix it is simply doing a code change to the resources in the deployment and then doing an entirely new deployment.

Based on the logs of the Lambda that runs this construct (see below), I was able to trace the error down to this line of code.

Based on a quick search of those errors, this seems to be a relatively common occurrence within Python for that library

Iā€™m not exactly sure what the remedy for this would be given its been transient and hard to reproduce, but weā€™ve run into this issue enough times that Iā€™ve figured its worth surfacing in case others run into it as well.

Some of the StackOverflow posts basically ended up not using the extractAll method and they implemented their own, but not sure if those all apply in this case.

Error Log

Here is an example of the logs from one class of failed deployment Iā€™ve seen (File name in directory ABC and header XYZ differ).

[ERROR]	2020-03-12T05:09:00.129Z	8339cb69-b6bc-4a9d-8a4e-7b611b7e242e	File name in directory 'static/js/2.7eee25fe.chunk.js.LICENSE' and header b'static/js/2.7eee25fe.chunk.js.LIC\xc4\xbdoS' differ.
Traceback (most recent call last):
  File "/var/task/index.py", line 101, in handler
    s3_deploy(s3_source_zips, s3_dest, user_metadata, system_metadata)
  File "/var/task/index.py", line 131, in s3_deploy
    zip.extractall(contents_dir)
  File "/var/lang/lib/python3.6/zipfile.py", line 1524, in extractall
    self._extract_member(zipinfo, path, pwd)
  File "/var/lang/lib/python3.6/zipfile.py", line 1577, in _extract_member
    with self.open(member, pwd=pwd) as source, \
  File "/var/lang/lib/python3.6/zipfile.py", line 1419, in open
    % (zinfo.orig_filename, fname))

Here is an example of the logs from the other class of failed deployment Iā€™ve seen (Bad CRC-32 for file ABC).

[ERROR]	2020-03-21T21:24:12.561Z	97098b50-04dc-4bf4-ab43-b89873817924	Bad CRC-32 for file 'static/js/runtime-main.664eb0cb.js'
Traceback (most recent call last):
  File "/var/task/index.py", line 101, in handler
    s3_deploy(s3_source_zips, s3_dest, user_metadata, system_metadata)
  File "/var/task/index.py", line 131, in s3_deploy
    zip.extractall(contents_dir)
  File "/var/lang/lib/python3.6/zipfile.py", line 1524, in extractall
    self._extract_member(zipinfo, path, pwd)
  File "/var/lang/lib/python3.6/zipfile.py", line 1579, in _extract_member
    shutil.copyfileobj(source, target)
  File "/var/lang/lib/python3.6/shutil.py", line 79, in copyfileobj
    buf = fsrc.read(length)
  File "/var/lang/lib/python3.6/zipfile.py", line 872, in read
    data = self._read1(n)
  File "/var/lang/lib/python3.6/zipfile.py", line 962, in _read1
    self._update_crc(data)
  File "/var/lang/lib/python3.6/zipfile.py", line 890, in _update_crc
    raise BadZipFile("Bad CRC-32 for file %r" % self.name)
  zipfile.BadZipFile: Bad CRC-32 for file 'static/js/runtime-main.664eb0cb.js'

I can dug up more examples if need be.

Environment

  • CDK CLI Version: 1.23.0
  • Module Version: 1.23.0
  • OS: macOS Mojave
  • Language: TypeScript (but likely all languages)

This is šŸ› Bug Report

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
ayush987goyalcommented, Apr 9, 2020

@rhermes62 No I am not renaming the zip. I am creating the zip like so and passing it to BucketDeployment:

const sourcePath = path.join(__dirname, 'path-to-source-dir');
const destinationZip = path.join(__dirname, 'dummyDir/temp.zip');
childProcess.execSync(`zip -r ${destinationZip} *`, { cwd: sourcePath });

new s3deploy.BucketDeployment(this, 'some-name', {
      sources: [s3deploy.Source.asset(destinationZip)],
      destinationBucket: destBucket
});
2reactions
rhermes62commented, Apr 6, 2020

I wonder, what is the size of the directory you try to deploy?

It is 1.9mb (it is the contents for a static website). Although itā€™s possible the static assets get corrupted, I doubt itā€™s the case. The assets are coming from a CI/CD system, and I get the errors even after retrying multiple times. I also manually checked the assets, and they are as we expect.

After having dealt with this more, I have a hunch that the BucketDeployment doesnā€™t handle when the same assets are re-deployed. In my original post, I had commented this:

ā€¦the only thing that has seemed to fix it is simply doing a code change to the resources in the deployment and then doing an entirely new deployment.

I have found that just going manual code changes in the assets which triggers a rename has fixed the deployments. We should probably go and test to see if we can get something reproducible based on this trend Iā€™ve found.

This all might be a red herring but briefly chatted with @ayush987goyal and his set up is deploying files with the same names which adds to the ā€œsame file name bugā€ theory.

Read more comments on GitHub >

github_iconTop Results From Across the Web

class BucketDeployment (construct) Ā· AWS CDK
BucketDeployment populates an S3 bucket with the contents of .zip files from other S3 buckets or ... The S3 bucket to sync the...
Read more >
How to upload a zip to S3 with CDK - Stack Overflow
In order to upload the zip file to a given bucket I ended up using BucketDeployment with a custom ILocalBundling .
Read more >
Stop Using the CDK S3 Deployment Module
This will be the main issue if you have websites with hundreds of pages. The BucketDeployment construct synthesizes a custom CloudFormationĀ ...
Read more >
awslabs/aws-cdk - Gitter
If your CDK module creates a bucket, you shouldn't use that. ... so create a bucket in your account, push your lambda .zips...
Read more >
@aws-cdk/aws-s3-deployment | Yarn - Package Manager
AWS S3 Deployment Construct Library. cdk-constructs: Stable. This library allows populating an S3 bucket with the contents of .zip files from other S3Ā ......
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