How to Connect AWS CodeBuild with a GitHub Repository

Kevin Tuei
4 min readJul 1, 2024

--

Introduction

In this article, we will go through a step-by-step process for setting up your GitHub Repository as the source for an Amazon Web Services (AWS) Pipeline using CodeBuild which gets triggered when a commit is made on the repository. Let’s get started.

Prerequisites

This process assumes that you already have the following:

  • An AWS Account
  • A GitHub Account
  • A Public GitHub Repository
  • An Open Source Application that can be uploaded to the Repository

Step 1: Access the AWS Code Pipeline Console

On the AWS Management Console, under Services, Search for CodePipeline

AWS Management Console

Step 2: Access the CodePipeline Console

Under the CodePipeline Console click Build — CodeBuild to expand the section then click on Getting Started. You will navigate to the CodeBuild Console where you can Click Create Project

AWS Codebuild Console

Supply the Project Name: All-in-Project

Under the Source Section, Select GitHub. You will have two options to authenticate CodeBuild to access your GitHub Repository; OAuth and GitHub Personal Access Token

In this guide, we will choose the OAuth option and then click on Connect to GitHub, a new window will pop up for us to log in to GitHub:

Pop Up Window

Review the permissions then click Authorize aws-codesuite

You will then log in to your GitHub by supplying the credentials then click Confirm

After authenticating you can choose the GitHub Repository

Select the Build Environment as per the needs of the Build Stage of your Pipeline, since that is not the focus of the article I will go with the defaults

Environment Options

For the Buildspec, I will avail a default Build Command:

Buildspec Options

You can also configure the Artifacts and Logs on the following sections, again I will go with the default options but uncheck Cloudwatch logs:

After unchecking, Click Create Build Project.

Create Build Project

After successful Project creation, we will update a file in the repo and commit for our first Build to be triggered. Note that there are no Builds in the Build History after the project is created.

Successful Project Creation

Start the Build and confirm that it is successful:

Updating hello.py in the GitHub Repository:

Commit the changes to the Main Branch and confirm that the Build is triggered on Code Build once set up successfully.

Conclusion

In this article, we successfully set up a connection between AWS CodeBuild and a Public GitHub Repository. We also confirmed that builds were successful, updated a file in the repository, and committed changes to the main branch.

You can further add tests and configure the Deploy stage of your CI/CD Pipeline after connecting the repository successfully.

--

--

Kevin Tuei

Making the world a better place through technology - Cloud Developer • Certified Educator • ALX Fellow • AWS Community Builder • Atlassian Community Leader