Skip to content

A demonstration of securely deploying a Node.js web application on AWS EC2 with IAM-based access control, environment variable protection, and step-by-step setup instructions for both local and cloud environments.

License

Notifications You must be signed in to change notification settings

RScrafted/aws-secure-webapp-deployment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js App — AWS Deployment

Table Of Content


1. Introduction

This project demonstrates AWS infrastructure setup and secure deployment of a Node.js web application. The application fetches live weather data from WeatherAPI.com and displays it in a browser UI.

The focus of this project:

  • Creating and configuring AWS resources securely
  • Deploying a working Node.js web app on AWS EC2
  • Keeping API keys private by using .env (excluded via .gitignore)

Notes

  • .env is excluded via .gitignore for security, therefore, each deployment requires manually creating .env
  • Feel free to leave your thoughts in discussion. And star the repo if you like the detailed approach.

2. Flow Diagram

flowchart TB
    subgraph Local
        A[Clone repo] --> B[Run setup.sh]
        B --> C[Create .env]
        C --> D[npm install & npm start]
        D --> E[Open localhost:3000]
    end

    subgraph AWS
        F[Create IAM user & EC2] --> G[SSH to EC2]
        G --> A
        E --> H[Visit public-ip:3000]
    end
Loading

3. AWS Deployment

  1. Create IAM user

    • Go to AWS IAM
    • Create user with Management Console access
    • Add to group aws-secure-webapp-deployment
    • Attach AmazonEC2FullAccess policy to group
  2. Log in with the new IAM credentials and open AWS Console.

  3. Launch EC2 instance

    • OS: Ubuntu
    • Download .pem key (e.g., setup.pem)
    • Create security group — allow inbound on port 3000
    • Note the public IP address
  4. Set permissions and connect

    chmod 400 setup.pem
    ssh -i "setup.pem" ec2-user@<public-ip>
  5. Follow the Common Setup Steps inside the EC2 instance.


4. Common Setup Steps

These steps are the same whether you are running the app locally or on the AWS.

  1. Clone the repository

    sudo apt install git -y
    git --version
    git clone https://github.com/RScrafted/aws-secure-webapp-deployment.git --progress
    cd aws-secure-webapp-deployment
  2. Run the setup script — Installs Git, Node.js, and npm

    chmod +x setup.sh
    ./setup.sh
  3. Create .env file (manual step — keeps API key private)

    cat > .env <<'EOF'
    PORT=3000
    WEATHER_API_KEY=your_api_key_here
    EOF
  4. Install dependencies and start the application

    npm install
    npm start

ensure, your pwd is aws-secure-webapp-deployment

  1. Test in browser

    • Local: http://localhost:3000
    • AWS: http://<public-ip>:3000

Important

Delete EC2 instance after the test to avoid unexpected AWS charges. Deleting IAM user and security group is optional but recommended.

About

A demonstration of securely deploying a Node.js web application on AWS EC2 with IAM-based access control, environment variable protection, and step-by-step setup instructions for both local and cloud environments.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published