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

前端 未结 5 1847
鱼传尺愫
鱼传尺愫 2021-01-04 01:59

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

相关标签:
5条回答
  • 2021-01-04 02:35

    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.

    0 讨论(0)
  • 2021-01-04 02:36

    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.

    0 讨论(0)
  • 2021-01-04 02:41

    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.

    0 讨论(0)
  • 2021-01-04 02:57

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

    0 讨论(0)
  • 2021-01-04 03:01

    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.
    0 讨论(0)
提交回复
热议问题