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.
4 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/
-
2Thanks a lot. I had the same problem with PHP script. It worked like a charm.– StrabekApr 29, 2016 at 12:54
-
-
1@daxiang28: Use PATH=$PATH:
ls -td /opt/elasticbeanstalk/node-install/node-* | head -1
/bin to add the node and npm executables to your path. Mar 23, 2018 at 11:44
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.
-
2
-
After the app is unzipped, it is first placed in a staging area before being copied into the designated app folder. For PHP, it's staged in
/var/app/ondeck
first. 1)/var/app/current
is moved to/var/app/current.old
2) then/var/app/ondeck
is moved to/var/app/current
If you need to perform any commands on the app folder, you can do so insidepost_actions.config
but target the changes against/var/app/ondeck
. For each platforms' specific context of where the folders are being copied, you can look into the logs located at/var/log/eb-activity.log
Mar 8, 2020 at 20:29
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
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.
-
2Unfortunately, no. Becouse EB create temporary folder which is trying to install app, if delpoy done EB move that to /var/app.... .– siavoltFeb 19, 2015 at 16:14