DEV Community

Cover image for Node.js Application Deployment on AWS Documentation ๐Ÿš€
Shubham Srivastava
Shubham Srivastava

Posted on

Node.js Application Deployment on AWS Documentation ๐Ÿš€

Introduction

This comprehensive guide walks you through the step-by-step process of deploying a Node.js application on AWS (Amazon Web Services). Follow these instructions to successfully set up and deploy your project.

Step 1: Clone the Repository

Begin by cloning the project repository to your local system using the following command:

git clone https://github.com/verma-kunal/AWS-Session.git
Enter fullscreen mode Exit fullscreen mode

Step 2: Testing the Project Locally

Set up the necessary environment variables in the .env file:

DOMAIN=""
PORT=3000
STATIC_DIR="./client"
PUBLISHABLE_KEY=""
SECRET_KEY=""
Enter fullscreen mode Exit fullscreen mode

Initialize and start the project:

npm install
npm run start
Enter fullscreen mode Exit fullscreen mode

Step 3: Set Up an AWS EC2 Instance

  1. Create an IAM User:

    • Generate an IAM user with Password Access and Admin Permissions.
  2. EC2 Instance Setup:

    • Log in to your AWS Console and create an EC2 instance.
    • Choose Ubuntu as the OS image and select the t2.micro instance type.
    • Create a new key pair and download the .pem file.
  3. Connecting to the Instance Using SSH:

    • Locate your .pem file and run the following commands:
     chmod 400 "Keyvalue.pem"
     ssh -i instance.pem ubuntu@<IP_ADDRESS>
    

    Result: ubuntu@ip-<IP_ADDRESS>:~$

Congratulations! Your AWS instance is now successfully set up locally.

Step 4: Configuring Ubuntu on Remote VM

Update outdated packages and dependencies:

sudo apt update
Enter fullscreen mode Exit fullscreen mode

Install Git, Node.js, and npm following the guides by DigitalOcean.

Installing Git

Configuring Node.js and npm

Step 5: Deploying the Project on AWS

Clone the project in the remote VM:

git clone https://github.com/verma-kunal/AWS-Session.git
Enter fullscreen mode Exit fullscreen mode

Create a .env file and set up environment variables using the vi command:

DOMAIN="http://localhost:3000"
PORT=3000
STATIC_DIR="./client"
PUBLISHABLE_KEY="your_publishable_key"
SECRET_KEY="your_secret_key"
Enter fullscreen mode Exit fullscreen mode

Set up an Elastic IP Address for your EC2 instance and use it as your DOMAIN.

Initialize and start the project:

npm install
npm run start
Enter fullscreen mode Exit fullscreen mode

Step 6: Configure Inbound Rules

Edit the inbound rules in the security group of your EC2 instance to allow traffic from the specific port.

Access your application at [AWS Public IP]:3000
Inbound Rules Configuration

Security Group Configuration

Congratulations! Your Node.js application is now successfully deployed on AWS. ๐ŸŽ‰

Feel free to access it through your configured DOMAIN and explore your deployed project. If you have any further questions or encounter issues, refer to the official AWS documentation or seek assistance from the AWS community. Happy coding! ๐Ÿš€

Top comments (0)