Self-hosted GitHub Actions runners using AWS CodeBuild

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.

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 the GitHub repository from the drop-down list.

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.

Leave the default values in the Environment section.

Choose Use a buildspec file in the Buildspec section.

And at the last step 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

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!”

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.

Leave a Reply

Your email address will not be published. Required fields are marked *