Jonathan Clark
Jonathan Clark

Reputation: 1260

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

Upvotes: 1

Views: 832

Answers (2)

Joe Lau
Joe Lau

Reputation: 459

For my case, it is because I created a file in Windows, which is saved with UTF-8 with BOM. I solved my case by saving it with encoding UTF-8 (without BOM) instead.

enter image description here

Upvotes: 1

Jonathan Clark
Jonathan Clark

Reputation: 1260

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.

Upvotes: 5

Related Questions