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
.envis excluded via.gitignorefor 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.
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
-
Create IAM user
- Go to AWS IAM
- Create user with Management Console access
- Add to group aws-secure-webapp-deployment
- Attach
AmazonEC2FullAccesspolicy to group
-
Log in with the new IAM credentials and open AWS Console.
-
Launch EC2 instance
- OS: Ubuntu
- Download
.pemkey (e.g.,setup.pem) - Create security group — allow inbound on port 3000
- Note the public IP address
-
Set permissions and connect
chmod 400 setup.pem ssh -i "setup.pem" ec2-user@<public-ip>
-
Follow the Common Setup Steps inside the EC2 instance.
These steps are the same whether you are running the app locally or on the AWS.
-
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 -
Run the setup script — Installs Git, Node.js, and npm
chmod +x setup.sh ./setup.sh
-
Create
.envfile (manual step — keeps API key private)cat > .env <<'EOF' PORT=3000 WEATHER_API_KEY=your_api_key_here EOF
-
Install dependencies and start the application
npm install npm start
ensure, your
pwdisaws-secure-webapp-deployment
-
Test in browser
- Local:
http://localhost:3000 - AWS:
http://<public-ip>:3000
- Local:
Important
Delete EC2 instance after the test to avoid unexpected AWS charges. Deleting IAM user and security group is optional but recommended.