aws / aws/aws-cdk

(aws-codecommit): Repository code initialization fails when empty files exist within the contents

Open
#19,012 19 comments 9 reactions 0 assignees View on GitHub
@aws-cdk/aws-codecommit bug effort/medium p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### What is the problem?

When attempting to initialize a CodeCommit repository with some `code` contents the stack fails with a `Code supplied is not a valid .zip archive` error if, among the contents, one or more empty files exist (eg. \_\_init\_\_.py).

This behavior applies to any of the supported [Code](https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_codecommit/Code.html) sources : `from_asset`, `from_directory`, `from_zip_file`.

### Reproduction Steps

```python
# Example with from_asset
dirname = os.path.dirname(__file__)
repository_code = Asset(
scope=self,
id="RepositoryCodeAsset",
exclude=[".vscode", "__pycache__"],
path=os.path.join(dirname, "code"),
)

aws_codecommit.Repository(
scope=self,
id="CodeCommitRepository",
repository_name="repository_name",
code=aws_codecommit.Code.from_asset(asset=repository_code),
)
```

The `code` folder shall contain one or more empty files.

### What did you expect to happen?

The stack should have been deployed successfully, the code commit repository `"repository_name"` should have been created and initiated with the contents from the `code` folder.

Also, the error message could have been more precise : the zip archive is perfectly valid, the issue (assuming there is one) is with its contents.

### What actually happened?

`cdk deploy` fails with a `Code supplied is not a valid .zip archive` error on the CodeCommit resource.

### CDK CLI Version

2.8.0 (build 8a5eb49)

### Framework Version

aws-cdk-lib==2.8.0

### Node.js Version

v16.10.0

### OS

MacOS 11.6.3

### Language

Python

### Language Version

Python(3.9.10)

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the failure with the Code.from_asset, Code.from_directory, and Code.from_zip_file entry points using a directory containing an empty file. Then trace the CodeCommit repository initialization path and its handling of the generated archive. Done means deployment succeeds with empty files present and any remaining validation error accurately describes the problem.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.