0
votes

I am trying to deploy some new code using aws codepipeline. The first time it works no problem, the second time the deployment fails because of existing files. How can I instruct my flow to overwrite existing files?

Error Message: The deployment failed because a specified file already exists at this location:

1
Can you specify what type of deployment you are doing? Maybe share a bit of the code, or an example bit of code, that represents the step in the pipeline that isn't working as you expect it to? - Jason Wadsworth

1 Answers

1
votes

I think the best way to deploy is to delete the project directory and kill the process before deploying. This let the state of the project directory keep pure and in sync with the original repository.

As you can see from this link(appspec.yml hooks for deploying to EC2), CodeDeploy download artifacts on Install phase and we cannot access to that step. Install phase comes after BeforeInstall hook.

So you should delete the directory and kill the processes before Install phase to be executed.

hooks:
   BeforeInstall:
     - location: codedeploy-scripts/deleteAndKill.sh
   #   runas: root # this might be needed depending on your setting.

Define codedeploy-scripts/deleteAndKill.sh properly and try running CodePipeline and CodeDeploy again.

P.S. Deleting the project directory and killing the processes are somewhat bothering. so once you use docker, what you have to do is only docker stop {container name} and docker run {image name}.