Amazon Elastic Beanstalk node and npm non-standard install locations

后端 未结 5 477
遥遥无期
遥遥无期 2021-01-30 01:41

Amazon Beanstalk installs node and npm into really obscure places - and I\'m not sure they won\'t change if EB decides to use a newer version of node, which would cause my appli

相关标签:
5条回答
  • 2021-01-30 02:12

    I created the file /.ebextensions/node.config in my project folder to declare my node version and add symlinks to the /bin folder. More information about the .ebextensions folder can be found here: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html

    option_settings:
      - option_name: NodeVersion
        value: 0.12.2
    files:
      "/bin/node" :
        mode: "755755"
        content: "/opt/elasticbeanstalk/node-install/node-v0.12.2-linux-x64/bin/node"
      "/bin/npm" :
        mode: "755755"
        content: "/opt/elasticbeanstalk/node-install/node-v0.12.2-linux-x64/bin/npm"
    
    0 讨论(0)
  • 2021-01-30 02:15

    You can add the most recent node and npm binaries to $PATH with a command like this:

    PATH=$PATH:`ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin
    

    I couldn't figure out how to prevent beanstalk commands from resetting the $PATH back again.

    If you are so inclined you can probably create a symlink with a command similar to the above and use that as your reference point in cron scripts etc.

    Agreed, it is very very annoying.

    0 讨论(0)
  • 2021-01-30 02:24

    We had a similar issue with "node not found", trying to run node in container commands. After running ps aux on the EC2 instance we saw that EB has access to the $NODE_HOME env var:

    su -s /bin/sh -c PATH=$PATH:$NODE_HOME/bin $EB_NODE_COMMAND 2>&1 nodejs
    

    This can be used in .ebextensions, e.g.:

    container_commands:
      your_node_script:
        command: 'env PATH="$PATH:$NODE_HOME/bin" ./bin/your_node_script'
    

    (thanks to Alan Grow)

    0 讨论(0)
  • 2021-01-30 02:29

    Amazon Elastic Beanstalk

    Grand the access to node command

    1. sudo su
    2. vipw
    3. nodejs:x:496:494::/tmp:/bin/bash (":wq" to save changes)
    4. sudo su nodejs
    5. PATH=$PATH:ls -td /opt/elasticbeanstalk/node-install/node-* | head -1/bin
    6. node -v (enjoy :)
    0 讨论(0)
  • 2021-01-30 02:32

    Following Peter Johnson & Greg Tatum replies I created a symlink to the latest node executable:

    container_commands:
      01_node_binary:
        command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/node /bin/node"
    
    • I find the latest version of the node install binary
    • Out of it I create a symlink in the /bin directory (which is part of the $PATH)
    0 讨论(0)
提交回复
热议问题