5

I am deploying via CodeDeploy a logstash configuration in a target instance in /etc/logstash/.

This is the last step in a 3-staged CodePipeline.

However it fails with message

The deployment failed because a specified file already exists at this location: /etc/logstash/pipelines.yml

How can I instruct CodeDeploy to overwrite files?

pkaramol
  • 16,451
  • 43
  • 149
  • 324
  • as my answer gets deleted because "it's not tailored", although i feel it is, see https://stackoverflow.com/questions/41590332/aws-codedeploy-fail-the-deployment-failed-because-a-specified-file-already-exis/44761130#44761130. – Seirddriezel May 15 '19 at 07:09

3 Answers3

6

March 2022 Update: Here are the docs on how to handle the file-exists-behavior: AppSpec 'files' Section.

July 2021 Update: Looks like AWS has finally acknowledged this defect -- look here for updates on all that.

August 2020 answer: The only way I have seen that you can overwrite files is selecting to overwrite or retain, as seen here, when you're creating a new deployment. In no other place will you see those settings. And if I'm not mistaken, this is the only way to do it because it is not supported on the CLI.

notnoahkirby
  • 309
  • 6
  • 17
0

An issue to add an overwrite option is open on GitHub and it has been there for quite a while. I solved this by adding a custom script in the BeforeInstallation hook which will erase all existing files before copying over my new deployment.

This is how my appspec.yml file looks like

version: 0.0
os: linux
files:
  - source: /
    destination: /path/to/destination
hooks:
  BeforeInstall:
    - location: DeploymentScripts/CleanupScript.sh
  AfterInstall:
    - location: DeploymentScripts/InstallScript.sh
      timeout: 600
  ApplicationStart:
    - location: DeploymentScripts/RestartScript.sh
      timeout: 3600
Sashi
  • 2,659
  • 5
  • 26
  • 38
  • This is already possible, but you have to initiate this in the command of the executing codedeploy. You can find more information docs.aws.amazon.com (strangely under 'rollback') cli docs.aws.amazon.com (see --file-exists-behavior (string)) – Seirddriezel May 14 '19 at 14:55
  • I found the `overwrite: true` setting in the `files:` section did not help. As mentioned, add some script commands to remove the files in the `BeforeInstall` hook. For example: `cd /path/to/app rm -rf *` – NJITman Apr 20 '21 at 15:35
-2

You can pass this attribute in the appspec.yml under

files : overwrite: true

  • 6
    [This issue](https://github.com/aws/aws-codedeploy-agent/issues/14) tells us that your solution is not currently supported. – notnoahkirby Aug 05 '20 at 21:31