Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute command after deploy AWS Beanstalk

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.

like image 269
siavolt Avatar asked Feb 18 '15 15:02

siavolt


2 Answers

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/

like image 99
siavolt Avatar answered Sep 18 '22 12:09

siavolt


A better approach would be to go with the aws platform hooks. Where you can define the postdeploy hooks AWS Patform Hooks

In that inside the project root directory you can add .platform/hooks/postdeploy/

Insdie this path you can create xxx-postdeploy-script.sh. Files here run after the Elastic Beanstalk platform engine deploys the application and proxy server.This is the last deployment workflow step

like image 30
Dheer Alim Avatar answered Sep 18 '22 12:09

Dheer Alim