Deploying a Node.js App to AWS EC2

Deploying a Node.js App to AWS EC2

In this blog post, we'll walk through the process of deploying a Node.js application to an AWS EC2 instance. We'll cover everything from setting up an IAM user to configuring security groups to ensure your application is accessible.

Prerequisites:

  • An AWS account
  • Basic understanding of the command line
  • Node.js and npm installed on your local machine
  • A Node.js application ready for deployment

Step 1: Create an IAM User

  1. Log into the AWS Management Console.
  2. Navigate to the IAM service.
  3. Create a new user with the necessary permissions to manage EC2 instances and security groups.
  4. Download the user's access key ID and secret access key.

Step 2: Launch an EC2 Instance

  1. Log into the AWS Management Console using your IAM user credentials.
  2. Navigate to the EC2 service.
  3. Launch a new instance, selecting a t2.micro instance type with an Ubuntu AMI.
  4. Configure the security group to allow inbound traffic on port 3000 (or the port your application uses).
  5. Create a key pair and download the private key.

Step 3: Connect to the EC2 Instance

  1. Use an SSH client to connect to your EC2 instance using the public IP address and private key.

Step 4: Install Node.js and npm

sudo apt update

sudo apt isntall nodejs

sudo apt install npm

#check if git is installed

git --version

git clone [email protected]:verma-kunal/AWS-Session.git

npm install        

Step 6: Set Up Environment Variables

  1. Create a .env file to store sensitive information like API keys , the setting up the app are listed here

Step 7: Configure Security Group

  1. In the AWS Management Console, navigate to the EC2 service.
  2. Select your instance's security group.
  3. Add an inbound rule to allow traffic on port 3000 from anywhere: Type: HTTP Protocol: TCP Port Range: 3000 Source: 0.0.0.0/0

Step 8: Access Your Application

  1. Use the public IP address of your EC2 instance to access your application in a web browser

https://your_ec2_public_ip:3000        


I successfully deployed my Node.js app to AWS EC2! ??

I learned how to set up an IAM user ?? to securely access my instance, launched a t2.micro instance ???, and SSH'd into it ??. I installed Node.js and npm ???, configured environment variables ??, and opened up the security group firewall firewall to allow incoming traffic.

Finally, I started my app with npm run start ?? and accessed it through the public IP address ??. This project boosted my skills in AWS, Linux, Node.js, and networking ??!


~Thank you

Happy learning


Mainak Lodh

MBA(Oil and Gas) | M.Tech(Nanotechnology) |B.Tech(ME) |

3 个月

Great work ??

Bristi Gayali

Software Testing | Requirement Analysis | Documentation | Test Plan & Test case

3 个月

Very informative

Arijit Ray

Jr Data analyst

3 个月

Very informative

要查看或添加评论,请登录

Ashmita Dutta的更多文章

社区洞察

其他会员也浏览了