Skip to content

EC2

appspec.yml
version: 0.0
os: linux
files:
  - source: /
    destination: /home/ec2-user
hooks:
  ApplicationStop:
    - location: scripts/stop.sh
      timeout: 60
      runas: root
  AfterInstall:
    - location: scripts/install.sh
      timeout: 60
      runas: root
  ApplicationStart:
    - location: scripts/start.sh
      timeout: 60
      runas: root

Scripts

Stop

stop.sh
#!/bin/bash
fuser -k 8080/tcp && echo "Stop Server" || echo "Not Running"

Install

  • Python
    install.sh
    #!/bin/bash
    cd /home/ec2-user
    yum install -y python3-pip
    pip install -r requirements.txt
    

Start

  • Python
    start.sh
    #!/bin/bash
    cd /home/ec2-user
    nohup python3 -u app.pyc > nohup.out 2>&1 &
    
  • Java
    start.sh
    #!/bin/bash
    cd /home/ec2-user
    filename=$(ls *.jar)
    nohup java -jar $filename > nohup.out 2>&1 &
    
  • Golang
    start.sh
    #!/bin/bash
    cd /home/ec2-user
    nohup ./main > nohup.out 2>&1 &