如何通过 EB 的 NodeCommand 调用多个命令?

How to invoke multiple commands via EB's NodeCommand?

上下文

给定 AWS 的 Elastic Beanstalk 上的一个简单节点应用程序(如 eb-node-express-sample)和默认的 nodecommand.config 文件如下:

option_settings:
  aws:elasticbeanstalk:container:nodejs:
    NodeCommand: npm start

问题

如何调用多个 bash 命令来代替 npm start?我希望能够做到以下几点:

    NodeCommand: echo 'Hello' && npm start

或:

    NodeCommand: |
      echo 'Hello'
      npm start

但似乎第一个单词之后的所有内容实际上都作为单个参数传入,导致 /var/log/nodejs/nodejs.log 中的以下输出:

'Hello' && npm start
'Hello' && npm start
'Hello' && npm start
...

# Logged repeatedly as the server tries and fails to start,
# apparently invoking `echo "'Hello' && npm start"` each time...

有没有办法绕过这个愚蠢的限制并直接 运行 多个 bash 命令?

动机

我有一个 Lerna 应用程序,它在根目录中没有任何有用的 start 脚本,在 packages/api/ 中有一个 start 脚本。我在这里的特殊需要是能够在 运行ning start 之前更改目录,但我正在寻找一个通用的解决方案来解决这个 运行ning 多个命令的问题。

我的解决方法是将脚本添加到 package.json:

"scripts": {
  "start": "node app.js",
  "start:eb": "echo 'Hello' && npm start"
}

用法:

option_settings:
  aws:elasticbeanstalk:container:nodejs:
    NodeCommand: npm run start:eb

万一它与其他人相关,我来到这里是因为服务器未启动导致 nginx 出现模棱两可的 502 Bad Gateway 错误,但 /var/log/nodejs/nodejs.log 中绝对没有。我终于意识到这是由于 NodeCommand 被 AWS 破坏了。