1

I am using aws code deploy to deploy a nodejs server to an ec2 instance.

aws code deploy agent downloads bundle to following path:

/opt/codedeploy-agent/deployment-root/deployment-group-id/deployment-id/deployment-archive/gulpfile.js

which means my gulpfile.js reside at

/opt/codedeploy-agent/deployment-root/deployment-group-id/deployment-id/deployment-archive/gulpfile.js

however any bash command I run will run from

/opt/codedeploy-agent

How do I change directory to dynamically generated

deployment-group-id/deployment-id/deployment-archive

and also install node modules from package.json?

ishandutta2007
  • 12,620
  • 12
  • 74
  • 99

3 Answers3

2

You may use the environment variables as for changing directory

$DEPLOYMENT_GROUP_ID/$DEPLOYMENT_ID/deployment-archive/

You can refer this for how to use them.

Ravi
  • 822
  • 6
  • 11
0

What I understand is you can not run BeforeInstall from root of your project, you have to move the code to AfterInstall.

To find the full path of root of after install and then navigate from there check this out: AWS CodeDeploy AfterInstall script is being run from code-deploy agent dir

Community
  • 1
  • 1
ishandutta2007
  • 12,620
  • 12
  • 74
  • 99
0

You can also change the root directory where code deploy adds the deployment-group-id/deployment-id/deployment-archive by changing it from the agent configuration file: https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-agent-configuration.html

By default it's in /opt/codedeploy-agent/deployment-root but you can change that.

Furthermore you can tell CodeDeploy to copy your files over to a different directory in the appspec file by controlling each file's source and destination:

https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-files.html