Execute command after deploy AWS Beanstalk

2019-02-22 15:15发布

I have problem with execute command after deploy, i have some node.js project and script, this script use some bin from node_modules, if i write my command for script in .ebextensions/.config he execute before npm install and return error ("node_modules/.bin/some": No such file or directory). How i can execute command after deploy. Thanks.

3条回答
对你真心纯属浪费
2楼-- · 2019-02-22 16:05

I found the following solution

I add to beanstalk config next command:

commands:
  create_post_dir:
    command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
    ignoreErrors: true
files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/some_job.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      cd /var/app/current
      export PATH=$PATH:$(ls -td /opt/elasticbeanstalk/node-install/node-* | head -1)/bin
      npm run some_script

This commands create(if not exist) folder for post-hooks scripts and adds bash script. Scripts in this folders execute only after npm install, this very important for my problem.

Thanks to this guy http://junkheap.net/blog/2013/05/20/elastic-beanstalk-post-deployment-scripts/

查看更多
够拽才男人
3楼-- · 2019-02-22 16:07

If you read the AWS ebextensions documentation they mention the execution, specifically where they mention that all commands are executed before the application version is deployed.

"You can use the container_commands key to execute commands for your container. The commands in container_commands are processed in alphabetical order by name. They run after the application and web server have been set up and the application version file has been extracted, but before the application version is deployed."

If you deploy it for a second time it should work; this is because your application is already unpacked. This however is not a working solution because every new instance that is spawned will error.

查看更多
贪生不怕死
4楼-- · 2019-02-22 16:13

create a file called .ebextensions/post_actions.config:

container_commands:
 <name of container_command>:
    command: "<command to run>"

this will be executed after the code was extracted, but before it was launched.

查看更多
登录 后发表回答