Introduction
Continuous Integration and Continuous Deployment (CI/CD) is a core practice in modern DevOps workflows. While GitHub Actions provides powerful cloud-hosted runners, sometimes you need more control over the build environment — for cost savings, performance, or custom setups.
In this tutorial, we’ll walk through setting up a self-hosted GitHub Actions runner on an AWS EC2 instance, and then use it to deploy a simple Node.js app automatically. You’ll learn how to:
Launch and configure an EC2 instance
Register it as a GitHub self-hosted runner
Set up a secure deployment pipeline
By the end, you’ll have a working CI/CD system running on your own AWS infrastructure.
✅ 1. Prerequisites
AWS account
GitHub account
Basic knowledge of Node.js & Linux
SSH key setup
✅ 2. Launching and Preparing the EC2 Instance
Choose Amazon Linux 2 or Ubuntu
Configure instance (t2.micro for testing)
Open required ports (e.g., SSH, app port)
-
SSH into EC2 and install:
- First update EC2
sudo apt update
- Install Docker
sudo apt-get install docker.io -y
- First update EC2
✅ 3. Installing and Registering GitHub Self-Hosted Runner
Go to your GitHub repo → Settings → Actions → Runners
Choose Linux x64
Download and configure the runner on EC2
✅ 4. Setting Up the CI/CD Workflow
Add at root level of your project
.github/workflows/deploy.yml
Refer this repo for yml file GitHub
✅ 5. Testing and Verifying Deployment
Push code to main branch
Watch self-hosted runner logs
Check if app is running (via browser or curl)
✅ 6. Troubleshooting Tips
- Open the required ports in AWS security group
✅ 7. Conclusion
-
What you’ve accomplished:
- EC2 instance as GitHub runner
- CI/CD using your infrastructure
-
Benefits of self-hosted vs GitHub-hosted runners
- Scale to multiple EC2 runners
- Add database integration
✅ 8. Resources & Links
GitHub
Top comments (0)