This project demonstrates how to host a simple website on an AWS EC2 instance using GitHub Actions and a self-hosted GitHub Actions runner.
The workflow automates the process of deploying website files from a GitHub repository to an AWS EC2 server whenever changes are pushed to the repository.
The project demonstrates a basic CI/CD workflow using:
- 🐙 GitHub – Source code repository
- ⚙️ GitHub Actions – Automation and deployment
- 🖥️ GitHub Actions Local/Self-Hosted Runner – Executes workflow jobs locally/on the configured machine
- ☁️ AWS EC2 – Server used for hosting the website
- 🌐 HTML/CSS – Simple website
The website is deployed on an AWS EC2 Ubuntu instance using GitHub Actions, a self-hosted runner, and Nginx.
🔗 GitHub to AWS EC2 Deployment
Instance State: Stopped
The AWS EC2 instance is currently stopped. Please contact the owner to request access to the website or required resources.
Developer
│
│ git push
▼
GitHub Repository
│
│ GitHub Actions
▼
Self-Hosted / Local Runner
│
│ Deployment
▼
AWS EC2 Instance
│
│ Web Server
▼
🌐 Hosted Website
The main objectives of this project are:
- Understand GitHub Actions workflows.
- Configure and use a self-hosted GitHub Actions runner.
- Connect GitHub Actions with an AWS EC2 instance.
- Automate website deployment.
- Understand the basic concept of CI/CD.
- Host a simple static website on AWS.
| Technology | Purpose |
|---|---|
| GitHub | Source code management |
| GitHub Actions | CI/CD automation |
| Self-Hosted Runner | Executes GitHub Actions jobs |
| AWS EC2 | Web hosting server |
| HTML | Website structure |
| CSS | Website styling |
| Linux | EC2 operating system |
GITHUB_ACTIONS/
│
├── .github/
│ └── workflows/
│ └── deploy.yml
│
├── index.html
│
└── README.md
A simple HTML website is created and stored in the GitHub repository.
<!DOCTYPE html>
<html>
<head>
<title>AWS EC2 Hosting</title>
</head>
<body>
<h1>Welcome to My AWS Hosted Website</h1>
<p>This website is deployed using GitHub Actions.</p>
</body>
</html>The website files are pushed to the GitHub repository.
git add .
git commit -m "Add website"
git push origin mainA GitHub Actions workflow is triggered when changes are pushed to the repository.
Example:
name: Deploy Website
on:
push:
branches:
- main
jobs:
deploy:
runs-on: self-hosted
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Deploy Website
run: |
echo "Deploying website..."
# Deployment commandsThe GitHub Actions job is executed using a self-hosted runner configured for the repository.
The runner receives the workflow instructions from GitHub and executes the required commands.
An AWS EC2 instance is used as the hosting server.
The EC2 instance runs a web server such as Apache or Nginx, which serves the website files.
Example:
sudo apt update
sudo apt install nginx -yThe website can then be placed in the web server's directory.
For Nginx:
/var/www/html/After the GitHub Actions workflow runs successfully, the website files are deployed to the EC2 instance.
The website can then be accessed using the EC2 instance's public IP address.
http://<EC2-PUBLIC-IP>
The overall deployment process is:
Code Change
↓
Git Push
↓
GitHub Repository
↓
GitHub Actions Triggered
↓
Self-Hosted Runner
↓
Deploy Files
↓
AWS EC2
↓
Web Server
↓
🌐 Website Live
For the website to be accessible from the internet, the EC2 Security Group should allow HTTP traffic.
Example inbound rules:
| Type | Port | Source |
|---|---|---|
| SSH | 22 | Your IP |
| HTTP | 80 | 0.0.0.0/0 |
Security Note: Avoid opening SSH (port 22) to
0.0.0.0/0unless necessary. Restrict it to your own IP whenever possible.
The project demonstrates:
- GitHub repository
- GitHub Actions workflow
- Self-hosted/local runner
- AWS EC2 instance
- Web server configuration
- Automated website deployment
- Live website hosted on AWS
Through this project, I learned:
- How GitHub Actions workflows operate.
- How to configure a self-hosted runner.
- How to deploy files using automation.
- Basics of AWS EC2 web hosting.
- Linux server administration.
- Basic CI/CD concepts.
- How source-code changes can trigger automated deployment.
This project can be extended by adding:
- Docker-based deployment
- Nginx reverse proxy
- HTTPS using Let's Encrypt
- Custom domain
- AWS IAM roles
- Automated rollback
- Docker Hub integration
- Kubernetes deployment
- Infrastructure as Code using Terraform
Krushna
GitHub: Oaklaan
⭐ If you found this project useful, consider giving the repository a star!