title: How to remove AWS CodeDeploy bundle.tar from instance after deploy
body: <p>I set up CodeDeploy with BitBucket. So I can deploy my latest commits via Bitbucket UI. But every deploy it creates a bundle.tar on instances to this directory <code>/opt/codedeploy-agent/deployment-root/</code> <a href="https://i.stack.imgur.com/1hXVU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1hXVU.png" alt="bundle.tar"></a></p>
  
  <p>I tried to add a hook <code>AfterInstall</code>, simple bash script that just finds and removes created bundle but it gives me an error now. Nothing in logs. Here is my appspec.yml file:</p>
  
  <pre><code>version: 0.0
  os: linux
  files:
    - source: /
      destination: /var/www/html/mysite.com
  permissions:
    - object: /var/www/html/mysite.com
      pattern: "**"
      owner: user
      group: www
      mode: 444
      type:
        - file
    - object: /var/www/html/mysite.com
      pattern: "**"
      owner: user
      group: www
      mode: 555
      type:
        - directory
  hooks:
    AfterInstall:
      - location: /usr/local/scripts/deploy/remove-bundle-after-deploy.sh
      timeout: 180
      runas: root
  </code></pre>
  
  <p>Here is the <code>remove-bundle-after-deploy.sh</code> file:</p>
  
  <pre><code>#!/bin/bash
  find /opt/codedeploy-agent/deployment-root/ -type f -name bundle.tar -exec rm -f {} +
  </code></pre>
  
  <p>How to set up CodeDeploy to not create bundle.tar files at all on my instances? Is that possible? If not, how can I remove them after successful deploy? </p>