将 npm db-migrate 与 Elastic Beanstalk 结合使用

Using npm db-migrate with Elastic Beanstalk

我正在尝试自动部署一个使用 npm db-migrate 的 nodejs 应用程序的 Elastic Beanstalk。我已经阅读了 Customizing Software on Linux Servers 的 AWS 文档,看来我应该使用容器命令。我创建了一个文件 10_db_migrate.config 并包含了这个命令:

container_commands:
  dbmigrate:
    command: "./node_modules/db-migrate/bin/db-migrate up -e production"
    leader_only: true

我尝试了多种路径组合,包括 /tmp/deployment/application/node_modules/... 但它们都返回以下错误:

INFO [2903] - [Application update code-pipeline-1579538046076-21b269f7103572f7a9d500d4158751de32e395c4@20/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild/postbuild_0_MyAppAPI/Command dbmigrate] : Activity execution failed, because: /usr/bin/env: node: No such file or directory (ElasticBeanstalk::ExternalInvocationError)

我错过了什么?

我成功了。部分问题是我试图让它变得比我需要的更难。我实际需要做的事情来自这个 post。下面是我的最终 container_command:

container_commands:
  00_node_binary:
    command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/node /bin/node"
  10_npm_binary:
    command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/npm /bin/npm"  
  20_dbmigrate:
    command: "./node_modules/.bin/db-migrate up"
    leader_only: true

我不久前发现了这一点,但我认为我还需要获取环境变量来执行我想做的事情。经过一些额外的测试后,我能够确定我不需要访问环境变量,所以这可以满足我的需要。仍然想知道如何引用环境变量以在 Elastic Beanstalk 上的 db-migrate 中创建准备好的语句,但现在更紧迫的需求。