DEV Community

Peter Klapcsik
Peter Klapcsik

Posted on

Self-hosted GitHub Actions runners using AWS CodeBuild

Introduction

I have always wanted to have the most efficient setup for the self-hosted GitHub Actions runners.
I think AWS recent announcement helps to approach this goal.

So I was keen to test it myself.

Instructions

Open the CodeBuild console and create a new project with the name aws-codebuild-github-action-self-hosted-runner. This name will be also used in the GitHub actions workflow at the runs-on parameter.

Open the CodeBuild console and create a new project

Select GitHub from the available Sources and select the default connect option Connect using OAuth.
You can find more details on GitHub OAuth here.

Select GitHub from the available Sources

Select the default connect option  raw `Connect using OAuth` endraw

Select the GitHub repository from the drop-down list.

Select the GitHub repository

Check the Rebuild every time a code change is pushed to this repository checkbox at the Primary source webhook events section.

Select WORKFLOW_JOB_QUEUED from the Event types.

Select  raw `WORKFLOW_JOB_QUEUED` endraw  from the Event types

Leave the default values in the Environment section.

Leave the default values in the Environment section

Choose Use a buildspec file in the Buildspec section.

Choose  raw `Use a buildspec file` endraw  in the Buildspec section

And at the last step click on Create build project.

Click on Create build project

After the project is created you can check if the required webhook exists in your repo.
Please use the following URL after you replace the words written in capital letters with your repo's related values:

https://github.com/USER-NAME/REPOSITORY-NAME/settings/hooks

Check if the required webhook exists in your repo

The last step is to create a workflow in your repo and then you can start using CodeBuild as your self-hosted GitHub action runner as a just-in-time runner.

name: Hello World

on: [push]

jobs:
  codebuild-job:
    runs-on: codebuild-aws-codebuild-github-action-self-hosted-runner-${{ github.run_id }}-${{ github.run_attempt }}
    steps:
      - run: |
          echo "Hello World!"
Enter fullscreen mode Exit fullscreen mode

You just need to add this GitHub Actions workflow yaml file to the following place in your repo and name the file as you like it. In my case it's codebuild.yaml:

.github/workflows/codebuild.yml

And when you commit and push this change the CodeBuild job just kicks off.

CodeBuild job just kicks off

Top comments (1)

Collapse
 
axel_fontaine_1c40fe93080 profile image
Axel Fontaine

If you want a cheaper version with an easier setup, sprinters.sh gives you ephemeral fast-booting runners on EC2 spot where you pick the EC2 instance type and storage you want and it only costs you a fraction.