Voiced by Amazon Polly |
Overview
Setting up a self-hosted runner on an Amazon EC2 machine for GitHub Actions workflows is a powerful way to customize and optimize your continuous integration and deployment (CI/CD) pipelines. This process allows you to leverage your own infrastructure while benefiting from the automation and scalability of GitHub Actions.
Pioneers in Cloud Consulting & Migration Services
- Reduced infrastructural costs
- Accelerated application deployment
Introduction
This document outlines the step-by-step process of creating and configuring a self-hosted runner on an Amazon EC2 machine. Once set up, the runner acts as a dedicated agent for executing jobs triggered by GitHub Actions workflows associated with your repository. Here’s a brief overview of the key steps involved:
Runner Flow
- Registration: Register the self-hosted runner with your GitHub repository. This involves obtaining a registration token from GitHub and configuring the registration token in the Self-Hosted Runner (Amazon EC2).
- Authentication: The self-hosted runner will authenticate with GitHub using the provided registration token once registered.
- Listening for Jobs: The self-hosted runner will continuously listen for incoming job requests from GitHub Actions workflows associated with the repository.
- Job Execution: When a job is triggered, GitHub dispatches it to an available self-hosted runner. The runner executes the job by cloning the repository, running the specified workflow steps, and reporting the results to GitHub.
- Cleanup: After completing the job, the self-hosted runner cleans up any temporary files and awaits further instructions
Step-by-Step Guide
The steps below detail creating and configuring a self-hosted runner on an Amazon EC2 machine for running your GitHub Actions workflows.
Steps:
- Download the Runner Package:
Connect to your Amazon EC2 instance using your preferred SSH client.
Create a directory to store the runner files:
Bash
1 |
mkdir actions-runner && cd actions-runner |
Download the latest runner package using curl. Replace the version number (v2.314.1) with the latest available version you want to use. You can find the latest version on the GitHub Actions releases page https://github.com/actions/runner/releases.
Bash
1 |
curl -o actions-runner-linux-x64-2.314.1.tar.gz -L https://github.com/actions/runner/releases/download/v2.314.1/actions-runner-linux-x64-2.314.1.tar.gz |
(Optional) Validate the Download:
Note: – Before proceeding, ensure the shasum command is available on your Amazon EC2 instance. You can check by running:
Bash
1 |
shasum –version |
This step verifies the package integrity using its SHA-256 hash. You can find the hash value for each release on the GitHub Actions releases page.
Bash
1 |
echo "6c726a118bbe02cd32e222f890e1e476567bf299353a96886ba75b423c1137b5 actions-runner-linux-x64-2.314.1.tar.gz" | shasum -a 256 –c |
If the hash values match, the download is valid. Otherwise, redownload the package.
Extract the Installer:
Bash
1 |
tar xzf ./actions-runner-linux-x64-2.314.1.tar.gz |
Execute sudo ./bin/installdependencies.sh to install any missing Dotnet Core 6.0 dependencies.
- Configure the Runner:
Run the configuration script:
Bash
1 |
./config.sh --url https://github.com/xxxxxx/xxxxxxx --token AQ5LI5U2SRPVTMF2RM272BLGBJNCQ |
Replace the following:
https://github.com/xxxxx/xxxxxxx: Replace with the URL of your GitHub repository.
AQ5LI5U2SRPVTMF2RM272BLGBJNCQ: Replace with a valid personal access token generated from your GitHub account with the repo scope. You can create a personal access token under Settings > Developer settings > Personal access tokens.
Conclusion
Proper setup and management of self-hosted runners on Amazon EC2 instances can significantly improve the efficiency and reliability of your development and deployment pipelines.
Drop a query if you have any questions regarding Amazon EC2 and we will get back to you quickly.
Making IT Networks Enterprise-ready – Cloud Management Services
- Accelerated cloud migration
- End-to-end view of the cloud environment
About CloudThat
CloudThat is an award-winning company and the first in India to offer cloud training and consulting services worldwide. As a Microsoft Solutions Partner, AWS Advanced Tier Training Partner, and Google Cloud Platform Partner, CloudThat has empowered over 850,000 professionals through 600+ cloud certifications winning global recognition for its training excellence including 20 MCT Trainers in Microsoft’s Global Top 100 and an impressive 12 awards in the last 8 years. CloudThat specializes in Cloud Migration, Data Platforms, DevOps, IoT, and cutting-edge technologies like Gen AI & AI/ML. It has delivered over 500 consulting projects for 250+ organizations in 30+ countries as it continues to empower professionals and enterprises to thrive in the digital-first world.
FAQs
1. Why use a self-hosted runner on an Amazon EC2 machine?
ANS: – Self-hosted runners offer greater customization and control over the execution environment than GitHub-hosted runners. Utilizing an Amazon EC2 machine allows you to leverage your existing infrastructure while integrating seamlessly with GitHub Actions workflows.
2. How do I obtain a registration token from GitHub?
ANS: – You can generate a personal access token with the “repo” scope from your GitHub account settings. This token is used during the configuration of the self-hosted runner.
3. Can I customize the AMI for the self-hosted runner?
ANS: – Yes, you can create a custom AMI with additional tools and configurations to suit your specific requirements. This allows for consistency and efficiency when deploying self-hosted runners.

WRITTEN BY Rajveer Singh Chouhan
Rajveer works as a Cloud Engineer at CloudThat, specializing in designing, deploying, and managing scalable cloud infrastructure on AWS. He is skilled in various AWS services as well as automation tools like Terraform and CI/CD pipelines. With a strong understanding of cloud architecture best practices, Rajveer focuses on building secure, cost-effective, and highly available solutions. In his free time, he keeps up with the latest advancements in cloud technologies and enjoys exploring infrastructure automation and DevOps tools.
Comments