5

When deploying an Elastic Beanstalk application, one of my hooks fails with "permission denied". I get the following in /var/log/eb-engine.log:

[INFO] Running platform hook: .platform/hooks/predeploy/collectstatic.sh

[ERROR] An error occurred during execution of command [app-deploy] - [RunAppDeployPreDeployHooks]. Stop running the command. Error: Command .platform/hooks/predeploy/predeploy.sh failed with error fork/exec .platform/hooks/predeploy/predeploy.sh: permission denied

How do I fix this?

Zags
  • 37,389
  • 14
  • 105
  • 140

2 Answers2

11

According to the docs, Platform hooks need to be executable. Of note, this means they need to be executable according to git, because that's what Elastic Beanstalk uses to deploy.

You can check if they are executable via git ls-files -s .platform; you should see 100755 before any shell files in the output of this command. If you see 100644 before any of your shell files, run git add --chmod=+x -- .platform/*/*/*.sh to make them executable.

Zags
  • 37,389
  • 14
  • 105
  • 140
-1

Create a file under .ebextensions folder with the right order and name it something like: 001_chmod.config

  # This command finds all the files within hooks folder with extension .sh and makes them executable.
container_commands:
  01_chmod1:
    command: find .platform/hooks/ -type f -iname "*.sh" -exec chmod +x {} \;

Source: https://www.barot.us/running-sidekiq-on-amazon-linux-2/

Ash
  • 1
  • 1
    I tried this approach and it doesn't work. It's pernicious because this works for regular deploys but not config updates. When you do a config update, your files get replaced with a fresh copy (where hooks are not executable) and container_commands don't get run (which is the fundamental problem), and as a result, hooks also don't get run because they aren't changed to be executable. – Zags Jan 07 '22 at 16:07