Skip to content

Fix non-deterministic zip output in cloudformation package#10421

Open
MsrOhkwr wants to merge 1 commit into
aws:v2from
MsrOhkwr:fix/make-zip-deterministic
Open

Fix non-deterministic zip output in cloudformation package#10421
MsrOhkwr wants to merge 1 commit into
aws:v2from
MsrOhkwr:fix/make-zip-deterministic

Conversation

@MsrOhkwr

Copy link
Copy Markdown

Issue #, if available:

N/A

Description of changes:

make_zip in artifact_exporter.py uses os.walk() without sorting, causing non-deterministic zip entry ordering. On Linux (ext4), readdir() returns entries in inode hash order, which varies when files are created in parallel (e.g., by npm ci). This results in different MD5 checksums (and thus different S3 keys) for aws cloudformation package across runs, even when directory contents are identical.

This change adds dirs.sort() and sorted(files) to ensure deterministic zip output regardless of filesystem behavior.

Reproduction: On CodeBuild (amazonlinux2-x86_64-standard:5.0, ext4), running aws cloudformation package twice against the same directory after npm ci produces different S3 keys. With this fix, repeated runs produce the same key.

Description of tests:

  • All 77 existing unit tests pass
  • Added test_make_zip_deterministic_order to verify entries are written in sorted order

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@MsrOhkwr MsrOhkwr requested a review from a team as a code owner June 18, 2026 08:56
The make_zip function uses os.walk() to enumerate files, but the
iteration order of directories and files is not guaranteed by the
filesystem (depends on readdir() implementation). On Linux/ext4,
this causes the zip entry order to vary between runs, producing
different MD5 checksums for identical content.

Sort directories and files during traversal to ensure deterministic
zip output regardless of filesystem behavior.
@MsrOhkwr MsrOhkwr force-pushed the fix/make-zip-deterministic branch from 6574f23 to 1a72be0 Compare June 18, 2026 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant