Is there a way to exclude a directory in AWS CodeDeploy?

Viewed 2910

We have an auto deployment from BitBucket set up to deploy to one of three EC2 instances. Everything currently works fine except our /data directory (which contains CMS-uploaded images, videos, etc) is not part of the repository. So during deployment, the existing /data directory on the specific instance is removed.

I see that it's possible to set exclusions for file ownership/group and permissions using the "exclude" parameter; however, no such parameter seems to exist for the Files section:

http://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-files.html

It seems as if this would be a common problem, but I haven't been able to find a solution yet. Does anyone have any suggestions for excluding files for overwriting during a deployment?

The only thing I can come up with at this point is to manually specify each directory that is to be overridden as well as each root file in appspec.yml. That's far from ideal, as it would need to be edited each time a new directory or root file is added.

4 Answers

Recently I face same problem. I need to exclude one file, but there are too many file in same directory and its hard to specify each file in appspec file. So I create two script file to run before and after install hook.

before_install.sh

#!/bin/bash
mv /path/to/file/need/to/exclude/on/deployment /path/to/temp/directory/which/will/not/update/on/deploment

above script move file to location which will be not update in deployment. after_install.sh

#!/bin/bash
mv /path/to/temp/excluded/file /path/to/file/exact/location

Above script place previous version of excluded file Add below lines in appspec.yaml

hooks:
  BeforeInstall:
    - location: /scripts/before_install.sh
  AfterInstall:
    - location: /scripts/after_install.sh
Related