title: AWS CodeDeploy script does not exist during AfterInstall hook
body: <p>I am having trouble with executing my install_dependencies.sh script in AfterInstall hook-</p>
  
  <p>it seems like my deployment-archive from which CodeDeploy agent is trying to run the scripts from does not yet exists during the AfterInstall hook.</p>
  
  <p>I am getting this error that causes my deployment to fail:</p>
  
  <pre><code>ERROR [codedeploy-agent(2643)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Error during perform: 
  InstanceAgent::Plugins::CodeDeployPlugin::ScriptError - 
  Script does not exist at specified location: /opt/codedeploy-agent/deployment-root/432f58a2-27d7-46c0-8091-1625eb8733af/d-Q3DGM6LPU/deployment-archive/scripts/install_dependencies.sh - 
  /opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:118:in `block (2 levels) in execute'...
  </code></pre>
  
  <hr>
  
  <p>my appspec.yml file looks like this:</p>
  
  <pre><code>version: 0.0
  os: linux
  files:
    - source: /
      destination: /home/ec2-user/myApp
  hooks:
    AfterInstall:
      - location: scripts/install_dependencies.sh
        timeout: 300
        runas: root
    ApplicationStop:
      - location: scripts/stop_server.sh
        timeout: 300
        runas: root
    ApplicationStart:
      - location: scripts/start_server.sh
        timeout: 300
        runas: root
  </code></pre>
  
  <hr>
  
  <p>for accessing the deployment-archive folder after the failed deployment attempt, i do get files in their correct path (the same path that appeared in the Error log):</p>
  
  <pre><code>[ec2-user@ip-172-31-10-87 scripts]$ cd  /opt/codedeploy-agent/deployment-root/432f58a2-27d7-46c0-8091-1625eb8733af/d-Q3DGM6LPU/deployment-archive/scripts/
  [ec2-user@ip-172-31-10-87 scripts]$ ls -ln
  total 12
  -rwxrwxrwx 1 0 0 261 Aug 21 13:33 install_dependecies.sh
  -rwxrwxrwx 1 0 0  69 Aug 21 13:33 start_server.sh
  -rwxrwxrwx 1 0 0  56 Aug 21 13:33 stop_server.sh
  </code></pre>
  
  <p>my EC2 instance os is-</p>
  
  <pre><code>[ec2-user@ip-172-31-10-87 ~]$ cat /etc/issue
  Amazon Linux AMI release 2018.03
  [ec2-user@ip-172-31-10-87 ~]$ uname -a
  Linux ip-172-31-10-87 4.14.62-65.117.amzn1.x86_64 #1 SMP Fri Aug 10 20:03:52 
  UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  </code></pre>
  
  <p>I have already checked for execution permissions, and the content of my script files is empty (with only "exit 0" statement) in order to help sandbox the problem.</p>
  
  <p>as far as i've seen in all examples- the scripts folder is expected to be in my deployed package and not outside of my deployment.</p>
  
  <p>my appspec.yml is in the root folder of my project, and so is my scripts folder.</p>
  
  <ul>
  <li>if I eliminate the AfterInstall/BeforeInstall hooks from my appspec- the problem does not occur. </li>
  </ul>
  
  <p>What am i missing? why does these file are not accessible during the AfterInstall/BeforeInstall hooks?</p>
  
  <p>please help,
  thanks </p>