Search code examples
node.jsamazon-web-servicesamazon-ec2pm2

EC2 instance shuts down when disconnected from Cloud 9 despite pm2 working


I have a website (Nodejs) on EC2 instance (Ubuntu) which is accessible and runs via pm2 process

Problem is - After closing IDE (cloud 9) the website stops working after some time, As soon as I login back to "Cloud 9" pm2 kick-starts automatically after EC2 Instance restarts. pm2 setup seems to be working fine that way. (I did run pm2 startup, pm2 save

From logs :

*PM2 log: App [app:0] exited with code [1] via signal [SIGINT]

PM2 error: Error: kill EPERM*

As mentioned in -- https://aws.amazon.com/cloud9/faqs/ AWS Cloud9 EC2 environment – Enables you to launch a new Amazon EC2 instance that Cloud9 connects to. By default, these instances stop 30 minutes after you close the IDE and start automatically when you open the IDE.

Does this means in PROD we can only do SSH so Instance does not stop and website remains live? Or how do I ensure Instance is not stopping?


Solution

  • You develop websites on Cloud9 machines that sit on an underlying EC2. They turn off after 30 mins as they are not meant for website hosting.

    You should be setting up an EC2 with a UserData script via CloudFormation to host the site.

    Or spinning it up using the CLI or SDK with your fav programming language.

    Or you may want to look into Elastic Beanstalk if you have no desire to learn AWS.

    If you want to host the site you can't do that off a Cloud9 machine, deploy to an EC2 or consider using Beanstalk.