0

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 Answers1

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.