Connecting Github to AWS Codepipeline
By: James Turner
Tags: Aws Codepipeline, Github, Continuous Integration, AWS

Connecting Github to AWS Codepipeline

So you want to know how to connect the dots between your Github account, and getting a successful continuous battle tested deployment into AWS. Read on…

Provisioning Credentials

Follow this pictorial guide for granting AWS access to your Github repository. Start by navigating to CodePipeline and begin by selecting “Create pipeline”. A quick forewarning; this will cost you $1/month 😱.

Create a pipeline

Name this pipeline whatever you want; I’ve named mine CREDENTIALS_ONLY. Choose to create a “new service role”, and append “CREDENTIALS_ONLY” to the end of it (you may want to go and delete this later). Then go ahead and hit “next”.

Create a source stage

Now in the “Add source stage”, select “Github (Version 2)” from the dropdown list and hit the “Connect to Github”.

Choosing Github (Version 2) source stage for codepipeline

Connect with your Github account

In the popup you get give the connection any old name, for the purposes of this example i’ve called mine “github-to-ci-in-5-minutes”. Then go ahead and hit the “connect to github” button.

Create a Github App (version 2) connection

Authorise AWS to access Github

Inside the subsequent a page click the “Authorise AWS Connector for GitHub”

Authorise AWS connector for Github

Now hit “Install a new app”

Github connection settings for AWS codepipeline

Pick the account you want to have it installed in

Pick an account to associate with the AWS codepipeline connector for Github

Pick your repository

Then either choose to allow this connection access to “All repositories” or just “Only select repositories”. In my case i’ll limit this just to the example repository I’m demonstrating from. Then go ahead and hit the “Install” button at the bottom.

Granting github repository access for AWS codepipeline

Confirm the Github connection

You should get a magic number filled in in the GitHub Apps box, and you can now press the “Connect” button.

GitHub Apps connection link number

This dialog will close and you should now be presented with a confirmation in your codepipeline source stage that you have “successfully connected to GitHub”.

Successful connection to Github for AWS codepipeline source stage

Cancel your pipeline creation

You can now “cancel” this pipeline. You have granted AWS codestar connectivity to your Github repositories.

Validate your new connectivity

You can validate this by performing the following command in a terminal, assuming you’ve installed https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html

aws codestar-connections list-connections \

--provider-type-filter Github --max-results 10 \

--query "Connections[?ConnectionStatus=='AVAILABLE']"

And you should have this hiding in your Github account settings

AWS connector for Github Apps (version 2)

Congratulations

You have now successfully connected your AWS account to your Github account. 👏 🥳

What now?

Want to know how you can use this to deploy that Github repository to AWS in the next 5 minutes? Look out for a forthcoming article that covers exactly this.