Search code examples
pythonamazon-web-servicesaws-code-deploy

AWS CodeDeploy failing in AfterInstall due to ScriptTimedOut


I have connected AWS to github

appspec.yml

version: 0.0
os: linux
files:
  - source: /
    destination: /home/mybot
hooks:
  AfterInstall:
    - location: RunMyBot.sh
      timeout: 300
      runas: root

RunMyBot.sh

#!bin/bash

cd /home/mybot/
yum install -y python3-pip python3 python3-setuptools
sudo python3 -m pip install --user --upgrade pip
pip3 install -r requirements.txt
python botMain.py

Error:

enter image description here

I want to run my main file - botMain.py, but it doesn't run.

I tried removing the install lines from script coz it said they were already installed, but still I was getting a timeout and my botMain.py was not running.


Solution

  • Probably it should be python3, not python. But anyway, your deployment hangs because if botMain.py is a server, it just starts and does not finish. Due to this, CD timeouts waiting for botMain.py to complete its execution which never happens.

    To properly run your botMain.py you should run it a daemon service. For that you can create custom unit file for systemd on linux. One example of that is here.