0
votes

I am trying to deploy an application on an EC2 instance using codepipeline in aws. I'm using codedeploy for this. I am successfully able to get the application from github and build it using codebuild but it fails at deployment with the following error. I am unable to understand what the issue is. I have tried updating node and npm in buildspec.yml file but appspec.yml is still not able to pull that updated version of node/npm. I'm new to aws. Does anyone know where its pulling these versions from and how to override them? Attached is the error. My package.json. appspec.yml. buildspec.yml. application_start.sh and builspec_yml.sh.

here is the error

[stderr]npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "server"
[stderr]npm ERR! node v6.17.1
[stderr]npm ERR! npm v3.10.10
[stderr]npm ERR! code ELIFECYCLE
[stderr]npm ERR! [email protected] server: `node server.js`
[stderr]npm ERR! Exit status 1
[stderr]npm ERR!
[stderr]npm ERR! Failed at the [email protected] server script 'node server.js'.
[stderr]npm ERR! Make sure you have the latest version of node.js and npm installed.
[stderr]npm ERR! If you do, this is most likely a problem with the react-tmp package,
[stderr]npm ERR! not with npm itself.
[stderr]npm ERR! Tell the author that this fails on your system:
[stderr]npm ERR! node server.js
[stderr]npm ERR! You can get information on how to open an issue for this project with:
[stderr]npm ERR! npm bugs react-tmp
[stderr]npm ERR! Or if that isn't available, you can get their info via:
[stderr]npm ERR! npm owner ls react-tmp
[stderr]npm ERR! There is likely additional logging output above.
[stderr]npm WARN Local package.json exists, but node_modules missing, did you mean to install?
[stderr]npm ERR! Linux 4.14.209-160.339.amzn2.x86_64
[stderr]npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "server"
[stderr]npm ERR! node v6.17.1
[stderr]npm ERR! npm v3.10.10
[stderr]npm ERR! path npm-debug.log.4097552080
[stderr]npm ERR! code EACCES
[stderr]npm ERR! errno -13
[stderr]npm ERR! syscall open
[stderr]
[stderr]npm ERR! Error: EACCES: permission denied, open 'npm-debug.log.4097552080'
[stderr]npm ERR! at Error (native)
[stderr]npm ERR! { Error: EACCES: permission denied, open 'npm-debug.log.4097552080'
[stderr]npm ERR! at Error (native)
[stderr]npm ERR! errno: -13,
[stderr]npm ERR! code: 'EACCES',
[stderr]npm ERR! syscall: 'open',
[stderr]npm ERR! path: 'npm-debug.log.4097552080' }
[stderr]npm ERR!
[stderr]npm ERR! Please try running this command again as root/Administrator.
[stderr]
[stderr]npm ERR! Please include the following file with any support request:
[stderr]npm ERR! /var/www/html/npm-debug.log

appspec.yml:

version: 0.0
os: linux
files:
  - source: /
    destination: /var/www/html/
hooks:
  ApplicationStart:
    - location: scripts/application_start.sh
      timeout: 300
      runas: ec2-user

application_start.sh:

#!/bin/bash

# Stop all servers and start the server as a daemon
cd /var/www/html/
forever stopall
nohup npm run server

buildspec.yml:

version: 0.2

phases:
  install:
    commands:
      - chmod +x scripts/buildspec_yml.sh
      - scripts/buildspec_yml.sh
  build:
    commands:
      - npm run start
artifacts:
  files:
    - '**/*'

scripts/builspec_yml.sh:

#!/bin/bash

nvm install 14.4.0
npm install -g npm@latest
npm i forever -g

Thank you for looking into this

1

1 Answers

0
votes

without any relation to aws, looking at your scripts/builspec_yml.sh script, it seems that you forgot to instruct nvm that you wish to use the version you install. try...

#!/bin/bash

# install and use node version
nvm install 14.4.0
nvm use 14.4.0

# print node and npm version
node --version
npm --version

# upgrade npm and install forever
npm install -g npm@latest
npm install -g forever

if you are using nvm, i will advise you to use .nvmrc and specify the node version there