How to Connect AWS CodeBuild with a GitHub Repository
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

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

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:

Review the permissions then click Authorize aws-codesuite

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



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

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

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.

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.

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.