0
votes

I am trying to automate my Elastic Beanstalk deployment of a nodejs app that uses npm db-migrate. I have read the AWS docs for Customizing Software on Linux Servers it seems I should be using a container command. I created a file 10_db_migrate.config and included this command:

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

I have tried many combinations for the path including /tmp/deployment/application/node_modules/... but they all come back with the following error:

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)

What am I missing?

1

1 Answers

1
votes

I got it working. Part of the problem was I was trying to make it more difficult than I needed. What I needed to actually do came from this post. Below is my final 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

I found this a while back but thought I also needed to get to the environmental variables to do what I wanted. After some additional testing I was able to determine that I didn't need to access the environmental variables so this worked for what I needed. Still would like to know how to reference environmental variables for creating a prepared statement in db-migrate on Elastic Beanstalk but more pressing needs right now.