DEV Community

kim-jos
kim-jos

Posted on

Deploying to AWS EC2

My team was building a project where users can write posts and comments (link). This project is mostly comprised of CRUD operations and used MongoDB. This post will be going over how I deployed this project using AWS EC2.

My experience with deploying an app in the past was mostly just firebase. Google makes it pretty easy for users to deploy their apps but this time I tried to use AWS because I really wanted to know why it was so widely used. The process was actually very different from firebase.

The first problem was that AWS provides so many services for deploying an app which makes it difficult to know which one is the right service for me. But in the end I chose EC2 because it's the service used by companies and I wanted to get some exposure to it.

I think the biggest difference between deploying with EC2 and firebase was that AWS actually provided me with a server (online computer). You have to actually choose an operating system. I went with the Linux operating system provided by Amazon because it was free. I think Ubuntu is another popular option. This whole process is called creating an "instance".

While you are creating an instance, it depends on what you are doing but if you are deploying a mini app you just have to set the security settings so that the ports that you use are open. Once you are done with that you are ready to launch your instance.

Your instance was launched, now you have to deploy your app on it. Because my app was built using Node.js I downloaded Node.js and git so that I can download my project using git commands. Once you download your app, you run it using "npm run start:prod" for Node apps. Then you are set to go! If you access the URL provided by AWS then you will see that your app is running live. But the problem is that once you shut your app down, the app stops running. To fix this problem you have to use a program that keeps it running at all times. There are multiple libraries that you can use to implement this such as "forever", "pm2", and etc. I used "pm2" because it was more widely used.

Top comments (0)