5

I'm trying to upload my NodeJS app into Elastic Beanstalk in Amazon AWS. But when npm install is executed it rises some permission denied and so it's unable to run the app. This is the log

Application update failed at 2018-10-02T15:18:14Z with exit status 1 and error: Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh failed.

+ /opt/elasticbeanstalk/containerfiles/ebnode.py --action npm-install
npm WARN deprecated tar.gz@1.0.7: ⚠️ WARNING ⚠️ tar.gz module has been deprecated and your application is vulnerable. Please use tar module instead: https://npmjs.com/tar
npm WARN deprecated fs-promise@2.0.3: Use mz or fs-extra^3.0 with Promise Support

> scrypt@6.0.3 preinstall /tmp/deployment/application/node_modules/scrypt
> node node-scrypt-preinstall.js

Error: Error: Command failed: ./configure
./configure: line 1904: config.log: Permission denied
./configure: line 1914: config.log: Permission denied


> keccak@1.4.0 install /tmp/deployment/application/node_modules/keccak
> npm run rebuild || echo "Keccak bindings compilation fail. Pure JS implementation will be used."


> keccak@1.4.0 rebuild /tmp/deployment/application/node_modules/keccak
> node-gyp rebuild

gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/tmp/deployment/application/node_modules/keccak/build'
gyp ERR! System Linux 4.14.67-66.56.amzn1.x86_64
gyp ERR! command "/opt/elasticbeanstalk/node-install/node-v8.11.4-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v8.11.4-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /tmp/deployment/application/node_modules/keccak
gyp ERR! node -v v8.11.4
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! keccak@1.4.0 rebuild: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the keccak@1.4.0 rebuild script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

┌──────────────────────────────────────────────────┐
│ npm update check failed │
│ Try running with sudo or get access │
│ to the local update config store via │
│ sudo chown -R $USER:$(id -gn $USER) /tmp/.config │
└──────────────────────────────────────────────────┘
Keccak bindings compilation fail. Pure JS implementation will be used.

> scrypt@6.0.3 install /tmp/deployment/application/node_modules/scrypt
> node-gyp rebuild

gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/tmp/deployment/application/node_modules/scrypt/build'
gyp ERR! System Linux 4.14.67-66.56.amzn1.x86_64
gyp ERR! command "/opt/elasticbeanstalk/node-install/node-v8.11.4-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v8.11.4-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /tmp/deployment/application/node_modules/scrypt
gyp ERR! node -v v8.11.4
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN cryptocms@0.1.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! scrypt@6.0.3 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the scrypt@6.0.3 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /tmp/.npm/_logs/2018-10-02T15_18_14_229Z-debug.log
Running npm install: /opt/elasticbeanstalk/node-install/node-v8.11.4-linux-x64/bin/npm
Setting npm config jobs to 1
npm config jobs set to 1
Running npm with --production flag
Failed to run npm install. Snapshot logs for more details.
UTC 2018/10/02 15:18:14 cannot find application npm debug log at /tmp/deployment/application/npm-debug.log

Traceback (most recent call last):
File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 695, in <module>
main()
File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 677, in main
node_version_manager.run_npm_install(options.app_path)
File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 136, in run_npm_install
self.npm_install(bin_path, self.config_manager.get_container_config('app_staging_dir'))
File "/opt/elasticbeanstalk/containerfiles/ebnode.py", line 180, in npm_install
raise e
subprocess.CalledProcessError: Command '['/opt/elasticbeanstalk/node-install/node-v8.11.4-linux-x64/bin/npm', '--production', 'install']' returned non-zero exit status 1.
Incorrect application version "nodecms_0.1.0" (deployment 3). Expected version "nodecms-0.1.0" (deployment 1).

I've looked for some solutions but no one has worked. I've also add this script in .ebextensions/00_change_npm_permissions.config to add root permission but has no effects.

files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/00_set_tmp_permissions.sh":
mode: "000755"
owner: root
group: root
content: |
  #!/usr/bin/env bash
  chown -R nodejs:nodejs /tmp

I'm new in Amazon AWS hoping that someone could help me to fix this problem.

I've tried also to put .npmrc file with unsafe-perm=true in the root of the NodeJS project (As described here: Beanstalk: Node.js deployment - node-gyp fails due to permission denied) but the problem persists

Philip
  • 553
  • 1
  • 5
  • 21

1 Answers1

13

So after trying everything the only solution that worked was to add an environment properties into Beanstalk console:

NPM_CONFIG_UNSAFE_PERM = true

Together with my previous attempt, EC2 was finally able to deploy my NodeJS project.

Philip
  • 553
  • 1
  • 5
  • 21