0

Issue on Laravel to deploy on Elasticbean stalk as I'm using one of the GitHub packages

https://github.com/rennokki/laravel-aws-eb

and I dropped the .ebextensions and .platform folders in my root project.

when I deployed and got an error, I decided to check the log report and it said it was due to a node.js

2021-10-20 10:48:34,072 [INFO] -----------------------Starting build-----------------------
2021-10-20 10:48:34,079 [INFO] Running configSets: Infra-EmbeddedPostBuild
2021-10-20 10:48:34,082 [INFO] Running configSet Infra-EmbeddedPostBuild
2021-10-20 10:48:34,086 [INFO] Running config postbuild_0_Ergnation_rowing
2021-10-20 10:48:34,103 [INFO] Command 00_copy_env_file succeeded
2021-10-20 10:48:36,241 [INFO] Command 01_install_composer_dependencies succeeded
2021-10-20 10:48:36,263 [ERROR] Command 02_install_node_dependencies (sudo npm install) failed
2021-10-20 10:48:36,263 [ERROR] Error encountered during build of postbuild_0_Ergnation_rowing: Command 02_install_node_dependencies failed
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 573, in run_config
    CloudFormationCarpenter(config, self._auth_config).build(worklog)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 273, in build
    self._config.commands)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/command_tool.py", line 127, in apply
    raise ToolError(u"Command %s failed" % name)
cfnbootstrap.construction_errors.ToolError: Command 02_install_node_dependencies failed
2021-10-20 10:48:36,266 [ERROR] -----------------------BUILD FAILED!------------------------
2021-10-20 10:48:36,266 [ERROR] Unhandled exception during build: Command 02_install_node_dependencies failed
Traceback (most recent call last):
  File "/opt/aws/bin/cfn-init", line 176, in <module>
    worklog.build(metadata, configSets)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 135, in build
    Contractor(metadata).build(configSets, self)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 561, in build
    self.run_config(config, worklog)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 573, in run_config
    CloudFormationCarpenter(config, self._auth_config).build(worklog)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 273, in build
    self._config.commands)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/command_tool.py", line 127, in apply
    raise ToolError(u"Command %s failed" % name)
cfnbootstrap.construction_errors.ToolError: Command 02_install_node_dependencies failed

I decided to check file and this file shows

02_install_node_dependencies:
    command: "sudo npm install"
    cwd: "/var/app/staging"

Seems it look correct method to install node.js

I have tried "Sudo yum install -y nodejs" and be deployed again but the console log keeps showing the error sudo npm install even I remove it and still showing error npm issue

02_install_node_dependencies (sudo npm install) failed
2021-10-20 11:48:45,727 [ERROR] Error encountered during build of postbuild_0_Ergnation_rowing: Command 02_install_node_dependencies failed
Traceback (most recent call last):
Steven Fleet
  • 27
  • 1
  • 7

1 Answers1

3

If you are using Amazon Linux 2 I recommend you to use Hooks, as you will have more control.

According to the docs:

On Amazon Linux 2 platforms, we recommend using Buildfile, Procfile, and platform hooks to configure and run custom code on your environment instances during instance provisioning.

You can still use commands and container commands in .ebextensions configuration files, but they aren't as easy to work with. For example, writing command scripts inside a YAML file can be challenging from a syntax standpoint

In this case, create the following file in your project

.platform/hooks/prebuild/install_node_js.sh

Here is the content of the file:

#!/bin/sh

# Install  Node  alongside with the paired NPM release

if [[ ! "$(node --version)" =~ "v12" ]]; then   
    sudo yum remove -y nodejs npm

    sudo rm -fr /var/cache/yum/*

    sudo yum clean all 

    curl --silent --location https://rpm.nodesource.com/setup_12.x | sudo bash -

    sudo yum install nodejs -y
fi

And that's it, deploy your code and you should have Node up and running.

Luis Montoya
  • 3,117
  • 1
  • 17
  • 26
  • 1
    Hi Luis, I know this is kinda old, but after searching a lot I don't find anything that works for me. I used the script and still got this error: `[ERROR] Unhandled exception during build: Yum does not have npm available for installation`. Any idea on how can I solve this? Thank you – Pol Frances Oct 27 '22 at 10:50