Search code examples
amazon-elastic-beanstalkdevops

AWS Elastic Beanstalk - hook not working exec format error


I'm trying to add a predeploy hook for AWS Beanstalk.

The file is

+-- .platform
    +-- hooks
        +-- predeploy
            +-- 01_npm_install_and_build.sh

With the following contents:

curl --silent --location https://rpm.nodesource.com/setup_16.x | sudo bash -
sudo yum -y install nodejs
cd /var/app/current/
sudo npm install
sudo npm run build

I've tested the code works by SSHing to the instance and running sh 01_npm_install_and_build.sh

by looking at the log file tail -f /var/log/eb-engine.log

I also tried postdeploy with the same issue, here's that error:

[ERROR] An error occurred during execution of command [app-deploy] - [RunAppDeployPostDeployHooks]. Stop running the command. Error: Command .platform/hooks/postdeploy/01_npm_install_and_build.sh failed with error fork/exec .platform/hooks/postdeploy/01_npm_install_and_build.sh: exec format error


Solution

  • The problem was that I was missing a "shebang" at the top of the sh script.

    The sh script should start with: #!/bin/bash... or see What is the preferred Bash shebang ("#!")? to check which shebang you should be using. which sh should give you an idea.

    Furthermore. /var/app/current/ isn't available at predeploy, so use /var/app/staging/ instead.