【问题标题】:AWS Beanstalk execute specific commandAWS Beanstalk 执行特定命令
【发布时间】:2018-07-23 06:40:45
【问题描述】:

我有一个仅适用于 sqlite 的示例 node.js 应用程序。
我想在 AWS ElasticBeanstalk 上进行“概念验证”,而无需重写 node.js 应用程序以使用受支持的数据库

为了启动 node.js 应用程序,我必须首先通过执行 node db.js 为 sqlite 数据库播种。

如何在 EBS 实例上执行此节点命令?

我尝试向 .ebextensions 添加命令

.ebextensions/foo.config

commands:
  1_seed_db:
    command: "PATH=$PATH:`ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin node db.js"

返回错误:

错误:找不到模块'/var/app/current/db.js;'

我怀疑 /var/app/current 目录还不存在,所以我也尝试修改 NodeCommand 使其执行自定义命令 node db.js; npm start as documented here:

.ebextensions/node.config

option_settings:
  - namespace: aws:elasticbeanstalk:container:nodejs
    option_name: NodeCommand
    value: node db.js; npm start

如何让 Elastic beanstalk 在启动节点进程之前执行node db.js

【问题讨论】:

    标签: javascript node.js sqlite amazon-web-services amazon-elastic-beanstalk


    【解决方案1】:

    我可以通过欺骗 packages.json 中的 start 命令来实现此功能

    packages.json 之前:

      "scripts": {
        "start": "node ./bin/www"
      },
    

    packages.json 之后:

    "scripts": {
      "start": "node ./db.js; node ./bin/www"
    },
    

    您显然不应该在生产环境中这样做,但它对于概念验证来说已经足够好了。

    【讨论】:

      猜你喜欢
      • 2015-04-19
      • 2016-04-19
      • 2017-04-07
      • 2018-05-23
      • 2019-04-03
      • 2018-05-25
      • 2015-09-15
      • 2016-10-08
      • 1970-01-01
      相关资源
      最近更新 更多