CodeDeploy is designed to deploy applications, not just copy a specific and constantly different set of files.
Thus, before deploying each โrevisionโ, CodeDeploy will first clear all files deployed by the previous version. Let me explain.
So, let's say the previous application deployment uploaded three files:
File A File B File C
And then the following deployment included only these files:
File A File C
Code Deploy will first clear the 3 files that it deployed in the first revision (A, B and C), and then deploy the new version ... It never just downloads the intended files, it always cleans up the old files first (determined by looking at the previous " editors "). This is important because it sheds some light on what seems like mysterious behavior in your case. The result, after deployment, of course:
File A File C
Now I wonder if you manually added files to the composition outside of CodeDeploy. It will clean only those things that it knows about, and will also not overwrite files in the current version if this cleaning phase does not delete them. This is often observed when people manually installed the application, and then tried to make CodeDeploy in the same folder ... there is no previous revision, so nothing needs to be cleared, and then it tries to copy over existing files and an error will occur. Usually you want your target folder to be bare so that you can run the change history correctly.
For example, in the previous scenario, if you preloaded the A, B, and C files manually, the deployment of the A and B files would fail, because it was not known to clear A, B, and C first, and then you get a message about error to overwrite files A and B.
A file (or folder) is completely beyond the scope of deployment ... i.e. is not part of any revision, say file D ... will not be affected and will remain happy there before and after deployment without complaint. This is useful for hosting data files and things that may be deployment specific, but are not necessarily part of a code base that you donโt want to constantly relocate.
Now you can do a lot of interesting things using hooks, of course, but this seems like the wrong tool to work with. Hooks are designed to perform functions such as stopping / starting a service, etc., so as not to control file copy control, which is the cornerstone of what CodeDeploy should do for you.
Excluding all files from the application specification (i.e., files not specified) and simply using the BeforeInstall and / or AfterInstall steps to execute the copy logic is an approach that may work for some scenarios.
In any case, perhaps this is a better understanding of how CodeDeploy works, can help you develop a solution. I do not think that he was especially well documented. My understanding comes from observing and dealing with it.