Ankita.eth
GithubContact
  • About Ankita
  • experience
    • TECHNOLOGIES
    • Frontend
      • Javascript
      • React
      • NextJS
      • HTML & CSS
      • UI Libraries & Frameworks
        • Tailwind CSS
        • Comprehensive Guide to UI Libraries and Frameworks
    • Backend
      • Node.js
      • Express.js
    • Database
      • Mongodb, Mongoose
      • PostgresSQl
      • MySQL
    • Packege Mangers
      • NPM-Node Packege Manager
      • Yarn
      • Yarn 2 (Berry)
      • PNPM
      • BUN
      • Commands cheatsheet
    • API Providers
      • Alchemy
      • Telegram Bot
      • CoinMarket
      • Thirdweb
      • Infura
      • Moralis
    • DevOps/Infrastructure
      • Docker
      • Kubernetes
      • CI/CD
      • Docker Swam
    • Protocols
      • ERCs & EIPs
        • ERC-20
        • ERC-721
        • ERC-1155
        • ERC-4337
        • ERC-6551
        • ERC-777
        • ERC-3643
        • EIP-7702
        • ERC-7715
        • ERC-7739
        • EIP-6780
        • EIP-5792
        • ERC-4626
        • EIP-1559
        • ERC-404
        • ERC-3643
        • ERC-223
    • Web3 Toolkits
      • Foundry
      • Hardhat
      • RemixIDE
    • Messaging/Caching
      • Kafka
      • Redis
      • Sendgrid
    • Blockchain
      • Solana
      • Ethereum
      • Polygon & Zero knowldge Proof
      • Bitcoin
      • Solidity
    • Deployment Platforms
      • AWS
      • Vercel
      • Heroku, Render
      • Domain setup
  • SDKs
    • Google Cloud SDK
    • AWS SDK
    • Firebase SDK
  • EOF EVM Object Format
  • Articles
    • Medium Articles
    • 🌐 My Work
  • 📞 Get in Touch
Powered by GitBook
On this page
  • 🌐 AWS Server Setup & Website Deployment
  • 1. AWS Login 🚪
  • 2. Log in to AWS Console 💻
  • 3. Launch an EC2 Instance 🚀
  • 4. Instance Details ⚙️
  • 5. Create and Connect to EC2 Instance 🔌
  • 6. Install Dependencies for Web Application ⚙️
  • 7. Upload Application Code 📁
  • 8. Set Up SSL 🔒
  • 9. Additional Configurations 🛠️
  • 10. DNS Setup 🌍
  • 11. Extra Commands & Tips 💡

Was this helpful?

  1. experience
  2. Deployment Platforms

AWS

🌐 AWS Server Setup & Website Deployment

1. AWS Login 🚪

Account Types

  • Root User: Main account holder, manages everything (email & password).

  • IAM User: Limited permissions for security (can only perform specific tasks).

2. Log in to AWS Console 💻

  • Log in to AWS Management Console.

  • Region Selection: Set to London (or choose your preferred region).

3. Launch an EC2 Instance 🚀

Steps:

  1. Navigate to EC2 Service:

    • Console > EC2 > Instances > Launch Instance.

  2. Instance Name and Tags:

    • Provide a name for the server, e.g., "Frontend Server", "Backend Server".

  3. Application and OS Images (Choose the OS for your server):

    • Options:

      • Ubuntu (Recommended) 🐧.

      • Amazon Linux.

      • macOS.

Example:

  • Select Ubuntu Server 22.04 LTS (HVM), SSD Volume Type.

4. Instance Details ⚙️

AWS Architecture Overview:

The architecture comprises:

  • Virtual Private Cloud (VPC) to isolate resources.

  • EC2 Instances to host the server.

  • S3 for object storage.

  • Security Groups for managing inbound/outbound traffic.

  • Select 64-bit (x86) for compatibility.

Instance Type

  • t2.micro: Suitable for small web apps, Free Tier (React Apps).

  • t2.small: Suitable for backend services (Paid).

Key Pair (Login) 🔑

  1. Click on Create new key pair.

  2. Provide a name for the project.

  3. Select File Type: .pem and Download.

    • Save it securely to access the server later.

Network Settings 🌐

  • Allow SSH Traffic from anywhere (tick).

  • Allow HTTPS and HTTP Traffic from the internet (tick).

Configure Storage 💾

  • Allocate 30 GB (default, gp2 SSD).

Advanced Details (Optional) ⚙️

  • No changes required here.

Summary 📝

  • Review all settings:

    • Number of instances: 1 or more based on requirements.

    • AMI: Ubuntu 22.04 LTS.

    • Instance Type: t2.micro or t2.small.

5. Create and Connect to EC2 Instance 🔌

Create the EC2 Instance 🖥️

  • Click Launch.

Connect to the Instance 📡

  1. Create IAM Role: Attach AmazonSSMFullAccess for secure access.

  2. Enable Fleet Manager host.

Connect Using SSH 🔐

chmod 400 project-key.pem
ssh -i "project-key.pem" ubuntu@<public-ip-address>

6. Install Dependencies for Web Application ⚙️

Become Super User

sudo su

Install Node.js & NPM 🌐

  1. Follow the guide here.

  2. Use the first option command.

  3. After installing Node.js:

npm install -g n
n lts
  • If you encounter errors, refer to the Node.js Package Manager Guide.

Install MongoDB 💾

Follow this tutorial.

If there are issues:

  1. Download libssl1.1:

wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb
sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb
sudo apt-get install -y mongodb-org

Install Nginx 🌐

  1. Follow this tutorial.

    • Use "Nginx Full" for firewall settings:

shCopy codesudo ufw allow 'Nginx FULL'
sudo ufw enable
sudo ufw status
sudo ufw reload

Install PM2 🔄

sudo npm install pm2 -g

7. Upload Application Code 📁

Upload Frontend & Backend Code

cd /var/www/html/

Install NVM (Node Version Manager) 🌐

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
source ~/.bashrc
nvm install --lts
npm install -g npm
npm install

Site Configuration for Nginx ⚙️

Unlink Default Config File

cd /etc/nginx/sites-available/
sudo unlink /etc/nginx/sites-available/default

Create New Config File for Frontend & Backend 🖊️

  1. Frontend Configuration Example:

server {
    root /var/www/html/frontend-build/;
    index index.html;
    server_name yourdomain.com;
    location / {
        try_files $uri /index.html;
    }
}
  1. Backend Configuration Example:

server {
    listen 80;
    server_name backend.yourdomain.com;
    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

Enable Configuration

sudo ln -s /etc/nginx/sites-available/example.conf /etc/nginx/sites-enabled

Test and Restart Nginx ⚙️

sudo nginx -t
sudo systemctl restart nginx

8. Set Up SSL 🔒

  1. Install Certbot:

shCopy codesudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt install certbot python3-certbot-nginx
  1. Generate SSL Certificate:

sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
  1. Renew Certificate:

sudo certbot renew --dry-run

9. Additional Configurations 🛠️

Start Services

sudo systemctl start nginx
sudo systemctl start mongod

Check Service Status

sudo systemctl status nginx
sudo systemctl status mongod

Add IAM Role for SSM 📊

  • Assign SSM Administrator access to connect easily via AWS Systems Manager.

10. DNS Setup 🌍

A Records and CNAME

  • Main Website: Use A Record pointing to instance IP.

  • Subdomain (same instance IP): Use CNAME Record.

  • Different IP: Use A Record.

11. Extra Commands & Tips 💡

  • List PM2 processes:

pm2 list
  • Check Certbot Certificates:

certbot certificates
  • If stopping and restarting the instance, update DNS with the new IP address.

Conclusion 🎉

AWS provides powerful and flexible tools to build scalable and secure infrastructure for your website. With these steps, you're on your way to mastering AWS deployments!

PreviousDeployment PlatformsNextVercel

Last updated 8 months ago

Was this helpful?