Search code examples
amazon-web-servicesamazon-ec2amazon-elastic-beanstalkamazon-linux-2

Elastic Beanstalk not executing hooks: "skipping hooks scripts under /opt/elasticbeanstalk/hooks/"


I'm trying to get Elastic Beanstalk (Amazon Linux 2, Node.js 16) to run some pre-deploy hooks. I'm using .ebextensions to create a hook in /opt/elasticbeanstalk/hooks/.

In .ebextensions, I have a file, 04_use_yarn.config:

files:
    "/opt/elasticbeanstalk/hooks/appdeploy/pre/49yarn.sh":
        mode:    "000775"
        owner:   root
        group:   users
        content: |
            #!/bin/bash

            # <Contents of the script I'm trying to run>

When SSHing into the instance, I can see that the 49yarn.sh file in /opt/elasticbeanstalk/hooks/appdeploy/pre/ is generated correctly. But during the deploy, I see that it logs "[WARN] skipping hooks scripts under /opt/elasticbeanstalk/hooks/". I can't find any documentation about what would make it skip the hooks in that directory.

How can I make it not skip my hook?

Here are the relevant logs from eb-engine.log:

2022/05/26 20:28:29.538686 [INFO] Executing instruction: StageApplication
2022/05/26 20:28:30.060239 [INFO] extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/
2022/05/26 20:28:30.060268 [INFO] Running command /bin/sh -c /usr/bin/unzip -q -o /opt/elasticbeanstalk/deployment/app_source_bundle -d /var/app/staging/
2022/05/26 20:28:36.070529 [INFO] finished extracting /opt/elasticbeanstalk/deployment/app_source_bundle to /var/app/staging/ successfully
2022/05/26 20:28:36.176851 [INFO] Executing instruction: RunAppDeployPreBuildHooks
2022/05/26 20:28:36.176873 [WARN] skipping hooks scripts under /opt/elasticbeanstalk/hooks/
2022/05/26 20:28:36.176890 [INFO] Executing platform hooks in .platform/hooks/prebuild/
2022/05/26 20:28:36.176934 [INFO] The dir .platform/hooks/prebuild/ does not exist
2022/05/26 20:28:36.176946 [INFO] Finished running scripts in /var/app/staging/.platform/hooks/prebuild

Solution

  • As per documentation:

    On Amazon Linux 2 platforms, custom platform hooks in the /opt/elasticbeanstalk/hooks/ folder are entirely discontinued. Elastic Beanstalk doesn't read or execute them.

    This is why the script(s) are being skipped.

    You will need to migrate over to platform hooks.