Keep modification time when zipping single file to avoid new checksum #3436
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
cloudformation package
command will upload a zip, e.g. for source of a lambda function. When referencing a directory, the files stays in-place when being zipped. However, when referencing a single file, a temporary directory is created and the file is copied there before the directory is zipped.Before, the file stats were not copied, leading to new modification times every time
cloudformation package
were run referencing a single file.This change also copies the file stats, ensuring the zip file gets the same checksum and filename as previous runs, and avoids an necessary upload and change set of the CFN stack, unless the source file gets a new modification time or changes content.
Partly solves #3131. However, the source file still needs to have the same modification time as previous to avoid a new checksum. In a CI-environment the file will probably get a different modification time for every checkout. This can be mitigated by forcing a modification timestamp on the source file, e.g. by
touch -t '200001010000' file.py
before runningcloudformation package
.I'm a bit unsure about the tests I've added. Don't like adding
time.sleep()
, but not sure how to test this otherwise.