Automate Your Website Deployment on AWS Lightsail

AWS Lightsail Automation

Deploy multiple websites effortlessly on a single Lightsail instance, with built-in SSL - using just one script.

Why Automate Website Deployment?

Manually setting up a server, copying files, configuring NGINX, and installing SSL certificates is repetitive and time-consuming. What if you could just answer a few prompts and have it all done for you? That's what this post is about.

We'll use a Bash script to:

  • Set up a folder for your website.
  • Extract your zipped website files.
  • Configure NGINX.
  • Set up a free SSL certificate using Certbot.

Let's dive in.

Step 1: Save the Automation Script

SSH into your instance:

ssh ubuntu@your-static-ip

On your instance, create a deployment script:

nano ~/deploy_website.sh

Paste this in:

#!/bin/bash
read -p "Enter your domain name (e.g., example.com): " DOMAIN
read -p "Enter the full path to your website ZIP file (e.g., /home/ubuntu/your-site.zip): " ZIPFILE
read -p "Enter your email address for SSL certificate: " EMAIL

DOC_ROOT="/var/www/html/$DOMAIN"
NGINX_AVAILABLE="/etc/nginx/sites-available/$DOMAIN"
NGINX_ENABLED="/etc/nginx/sites-enabled/$DOMAIN"

sudo mkdir -p "$DOC_ROOT"
sudo unzip -o "$ZIPFILE" -d "$DOC_ROOT"
sudo chown -R www-data:www-data "$DOC_ROOT"

sudo tee "$NGINX_AVAILABLE" > /dev/null 
server {
    listen 80;
    server_name $DOMAIN www.$DOMAIN;

    root $DOC_ROOT;
    index index.html;

    location / {
        try_files \$uri \$uri/ =404;
    }
}


sudo ln -sf "$NGINX_AVAILABLE" "$NGINX_ENABLED"
sudo nginx -t && sudo systemctl reload nginx

sudo certbot --nginx -d "$DOMAIN" -d "www.$DOMAIN" --email "$EMAIL" --agree-tos --no-eff-email

echo -e "\n✅ Your site is live at: https://$DOMAIN"

Make it executable:

chmod +x ~/deploy_website.sh

Step 2: Upload Your Website Files

Use SCP to upload your website ZIP file to the server:

scp /path/to/your-site.zip ubuntu@your-static-ip:/home/ubuntu/

This uploads the file to the home directory of your Lightsail instance, which the script will unzip and deploy.

Make sure the ZIP contains your index.html at the top level or inside a single folder.

Step 3: Deploy with a Single Command

Now run the script:

./deploy_website.sh

You'll be prompted for:

  • Domain name (e.g., yourdomain.com)
  • Path to ZIP file (e.g., /home/ubuntu/your-site.zip)
  • Email address for SSL

✨ After this, your site is live with SSL! You only answered a few questions.

Adding More Websites Later

Simply upload a new ZIP file and rerun the script. It'll:

  • Create a new directory under /var/www/html
  • Extract your project files
  • Configure and reload NGINX
  • Secure the domain with SSL

Zero manual steps. Instant launch.

Conclusion

With just one reusable script, you've eliminated manual configuration and turned Lightsail into your personal hosting platform.