Deploying and Exposing a NodeJS Application to the External World with AWS EC2

Deploying and Exposing a NodeJS Application to the External World with AWS EC2

πŸ“ Introduction:

Hi Everyone, welcome to Day-12 of our learning series. In this session, we will cover how to deploy and expose a NodeJS application to the external world using AWS EC2. We will provide a live example and the source code is available on our GitHub repository.

πŸ”Ή Session Content:

  1. Creating an IAM User and Login: The first step is to create an IAM (Identity and Access Management) user and login to AWS. IAM allows you to manage users and their access to AWS services.

  2. Creating an EC2 Instance: We will then cover how to create an EC2 instance. EC2 is a virtual server in the cloud and it is essential to have good practices when creating instances. We will discuss some of these practices.

  3. Accessing the EC2 Instance: Once the instance is created, we will learn how to access it through the command line interface or a web browser.

  4. Deploying an Application on AWS EC2: Next, we will cover how to deploy a NodeJS application on AWS EC2. We will provide step-by-step instructions and discuss best practices.

  5. Exposing the Application to the Outside World: After deploying the application, we will demonstrate how to expose it to the outside world. This will allow users to access the application from anywhere with an internet connection.

  6. Accessing the Application Deployed on AWS from Your Laptop: Finally, we will show you how to access the application deployed on AWS from your laptop.

πŸ”ΉSummary:

In this session, we covered the process of deploying and exposing a NodeJS application to the external world using AWS EC2. We discussed the steps involved in creating an IAM user, creating an EC2 instance, accessing it, deploying an application, and exposing it to the outside world. We hope this session was helpful and informative for you. You can find the source code on our GitHub repository for further reference. Thank you for attending this session.

πŸ“ Steps to follow along:

πŸ”Ή Deploying a Node Js Application on AWS EC2

⚜Testing the project locally

  1. Clone this project
git clone https://github.com/verma-kunal/AWS-Session.git
  1. Setup the following environment variables - (.env) file
DOMAIN= ""
PORT=3000
STATIC_DIR="./client"

PUBLISHABLE_KEY=""
SECRET_KEY=""
  1. Initialise and start the project
npm install
npm run start

⚜ Set up an AWS EC2 instance

  1. Create an IAM user & login to your AWS Console

    • Access Type - Password

    • Permissions - Admin

  2. Create an EC2 instance

    • Select an OS image - Ubuntu

    • Create a new key pair & download .pem file

    • Instance type - t2.micro

  3. Connecting to the instance using ssh

ssh -i instance.pem ubunutu@<IP_ADDRESS>

⚜ Configuring Ubuntu on remote VM

  1. Updating the outdated packages and dependencies
sudo apt update
  1. Install Git - Guide by DigitalOcean

  2. Configure Node.js and npm - Guide by DigitalOcean

⚜ Deploying the project on AWS

  1. Clone this project in the remote VM
git clone https://github.com/verma-kunal/AWS-Session.git
  1. Setup the following environment variables - (.env) file
DOMAIN= ""
PORT=3000
STATIC_DIR="./client"

PUBLISHABLE_KEY=""
SECRET_KEY=""

For this project, we'll have to set up an Elastic IP Address for our EC2 & that would be our DOMAIN

  1. Initialise and start the project
npm install
npm run start

NOTE - We will have to edit the inbound rules in the security group of our EC2, in order to allow traffic from our particular port

πŸ“ Resources:

⚜ Follow Prasad Suman Mohan for many such contents:

Did you find this article valuable?

Support Prasad Suman Mohan by becoming a sponsor. Any amount is appreciated!

Β