Q:

Elastic Beanstalk run post deploy script

My node.js app consists of two things, an express backend and a react frontend.
I have two package.json files in this structure
package.json 
/app/package.json

What I want to do is run a script in my frontend folder, app, that builds my code.
the script I want to run is npm install and npm run build
How do I run this script after a deploy have happened?
commands:
    01_app_npm_install:
        command: npm install
        cwd: app/
    02_app_npm_build:
        command: npm run build
        cwd: app/

But it returns an error saying that "No such file or direc
tory: 'app/'."
Is this possible to do on aws elastic beanstalk?

A:

Update:
This is now much more developed and defined.
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html
Original:
I haven't done nodejs myself with Elastic Beanstalk, but I have done a lot of Django.
The commands: section runs before the project files are put in place. This is where you can install server packages for example.
The container_commands: section runs in a staging directory before the files are put in its final destination (which is /var/app/current it seems for nodejs). Here you can modify your files if you need to.
Reference for above:
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html
You can also run a post deploy scripts. This is not very well documented (at least it wasn't). You can do something like this:
files:
    "/opt/elasticbeanstalk/hooks/appdeploy/post/99_restart_delayed_job.sh":
        mode: "000755"
        owner: root
        group: root
        content: |
            #!/usr/bin/env bash
            service httpd restart

A:

Thanks to @gustaf and some other sites I managed to pull a solution together. It's not pretty but it works.
I created a file in .ebextensions/01_build.config 
commands:
  create_post_dir:
    command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
    ignoreErrors: true
files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/99_build_app.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      cd /var/app/current/app/
      sudo /opt/elasticbeanstalk/node-install/node-v6.2.2-linux-x64/bin/npm install
      sudo /opt/elasticbeanstalk/node-install/node-v6.2.2-linux-x64/bin/npm run build

hard coding the node-version is not perfect but it works for now.

