AWS CodeDeploy Fail: The deployment failed because a specified file already exists at this location

This is possible! This is an option during a deployment: "Content options: Choose the action for AWS CodeDeploy to take during a deployment when a file on a target instance has the same name as a file in the application revision, for the same target location."

You can choose fail, overwrite and retain. Retain is probably the best choice in your case.

You can find more information

  • docs.aws.amazon.com (strangely under 'rollback')

  • cli docs.aws.amazon.com (see --file-exists-behavior (string))


If you just want the error to go away, you can use one of the earlier Lifecycle Hook scripts (BeforeInstall maybe) to delete that folder before the source gets re-added in a later Hook. If the source doesn't get re-added in a later Hook, add it yourself.

I was getting this error even on new instances, so CodeDeploy must be caching that folder somehow, then getting upset that it did so.