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

倖福魔咒の 提交于 2019-11-30 22:46:37

问题


I am trying to set AWS Code deploy with Github to automate my deloyment. the problem i am having is the ec2 instance is already active and has the web app code. the problem is there is also other content on the instance that I don't want under source control. Code deploy is failing with the following error:

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

this is because the source code is on the instance and was not added as a revision.

So my question is there any way to make the code deploy recognise the current files on the instance as an inital revision?


回答1:


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))




回答2:


You can simply delete the entire contents of your web root and allow CodeDeploy to update it. Any type of deployment will replace the entire contents.

If you're feeling unsure then copy the webroot to another folder, and in the very unlikely event of a failure you can copy it all back.

Deployments often fail when a file has been modified on the disk, I assume CodeDeploy is checking the modified time of the file.




回答3:


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.




回答4:


I had same issue when working in CodeDeploy with EC2 Instances.

  • I removed EC2 Instances from AWS CodeDeploy Deployment Group. I added new EC2 instances to the deployment group.
  • Otherwise, Replace new deployment group with an existing deployment group.



回答5:


The issue is that CodeDeploy maintains a cleanup file that it updates after every deployment. These are the files it will delete before installing the new ones. You could of course create this yourself, but that's hard. The point of CodeDeploy is to make things easy. This is what I did (Note: My app has a lot of files and I was about to find something other than CodeDeploy that actually made transitioning to it easy instead of painful and stupid, and then I formulated this approach; if you have a small number of files, it might be easier to create a BeforeInstall script or delete them manually):

  1. create a free-tier EC2 instance (t2.micro). If your app is giant, you may need more disk space, so adjust as necessary. THIS WON'T BE RUNNING YOUR APP!

  2. Create a new deployment group pointing to that new instance.

  3. Create a new YAML that doesn't actually do any BeforeInstall or AfterInstall tasks. You are not trying to run your app. You are literally moving files over. This is so that you can grab that cleanup file.

  4. After deployment, ssh into the ec2 instance (remember to allow SSH in the Security Group!) and go to /opt/codedeploy-agent/deployment-root/deployment-instructions/

  5. You will see {deployment-group-identifier}-cleanup. scp this to the ec2 instance on which you actually want to run your app. Or, FileZilla it out onto your main machine and then onto the main ec2 instance. That was the easiest choice for me, because my local machine already had all the right keys.

  6. SSH into the main ec2 instance and move the cleanup file into the /opt/codedeploy-agent/deployment-root/deployment-instructions/ if it isn't already there. Note the failed {deployment-group-identifier} and replace the cleanup file's {deployment-group-identifier} with the failed identifier.

  7. Rerun the deployment.

8.???

  1. Profit.

I will provide more in-depth instructions for each of these steps (except for 8 and 9... which will go away) when I have time.



来源:https://stackoverflow.com/questions/41590332/aws-codedeploy-fail-the-deployment-failed-because-a-specified-file-already-exis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!