我有一个用NodeJS编写的Web服务器和前端的Angular。
结构就像这样
musicapp
|-- server
| |--- src/
| |--- node_modules/
| |--- package.json
|--- client
|--- src/
|--- node_modules/
|--- package.json
当我使用eb deploy
部署到Elastic Beanstalk时没有任何反应,我已经意识到这一定是因为Elastic Beanstalk的默认操作是调用npm install
和npm start
但是在我的case,在root上调用时不会执行任何操作。
所以我的问题是,我如何告诉Elastic Beanstalk:部署后,cd
到客户端,然后将npm install
,npm run build
和cd
调用到服务器并致电npm install
,npm start
?
我在EB文档中找不到任何解释如何执行此操作的内容。
答案 0 :(得分:3)
在根文件夹中创建一个名为.ebextensions
的目录,并在该文件夹中创建一个名为01_npm.config
的文件(例如)。
在该yaml文件中,您可以通过以下方式指定命令:
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
当您自动运行eb deploy
时,Elastic Beanstalk将执行这些命令。
有关更多信息,请参阅: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html