Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you customize a NodeJS deployment to Elastic Beanstalk?

I have a web application written with NodeJS for the webserver and Angular on the frontend.

The structure is like this

musicapp
   |-- server
   |     |--- src/
   |     |--- node_modules/
   |     |--- package.json
   |--- client
         |--- src/
         |--- node_modules/
         |--- package.json

When I deploy to Elastic Beanstalk using eb deploy nothing happens, and I've realized it must be because the default action for Elastic Beanstalk is to call npm install and npm start but in my case, that doesn't do anything when called on the root.

So my question is, how do I tell Elastic Beanstalk: upon deploy, cd to client and call npm install, npm run build and then cd to server and call npm install, npm start ?

I can't find anything in the EB documentation that explains how one might do this.

like image 531
shad-chan Avatar asked Oct 17 '25 03:10

shad-chan


1 Answers

In your root folder create a dir called .ebextensions and inside that folder create a file called 01_npm.config (for example).

In that yaml file you can specify commands by:

container_commands:
  01_client:
    command: "cd ./server && npm install && npm run build"
    leader_only: true
  02_server:
    command: "cd ./client && npm install && npm run build"
    leader_only: true

Elastic Beanstalk will execute those commands when you run eb deploy automatically.

For more information see: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html

like image 161
nrhode Avatar answered Oct 19 '25 20:10

nrhode



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!