I have a simple node application running on the EC2 instance, everything is working just fine and I want to integrate this application with CircleCI for the continuous deployment. I have been following this article where it says to SSH to the EC2 instances and then run your deployment commands.

I've created a basic deploy.sh file in the EC2 instance, where I simply change the directory to project directory and then run npm i and pm2 delete all with pm2 start server.js. Now before testing it out my circleCI I thought of checking if it's working in general or not, so

  1. When I run this deploy.sh file from within EC2 instance, it works fine and follows all the steps to install node_modules and then serving the application with pm2 correctly. So, no issues here.
  2. From my local machine when I tried to run the same deploy.sh with this command ssh -i <my-pem-file> <ec2-user>@<ec2-ip> \ ./deploy.sh. it echoes the basic stuff but says npm and pm2 : not found . The reason this is happening is because that deploy.sh file is being run in context of my local machine (or not?).

So how can I simply run this deploy.sh file right after I SSH to my EC2 instance from circleCI, or If there is some better approach to do this all together.

1 Answer 1


I would look at AWS System Manager to do this instead of direct ssh. Create a SSM document to run the commands you want to run, then this can be invoked by an AWS cli command from your CI/CD pipeline.

We do something the same to update configuration files from an s3 bucket, run as part of a Gitlab pipeline.

  • Hi @Alastair Montgomery , thanks for suggestion to use SSM instead of SSH. I tried to invoke the deploy.sh placed under my ec2 instance by using the runshellscript command, but its not able to run npm commands, tried using runasuser. Any pointer to fix this, thanks! Jun 20, 2021 at 8:35
  • Might be something to do with the environment it's getting with SSH or SSM is running the script. For example might not have npm on the path. Try referencing it using the commands full path in your script. Jun 20, 2021 at 21:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.