Connecting Github to AWS Codepipeline
A verbal and pictorial guide to allow AWS access to a Github account for use with 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”.
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.
Authorise AWS to access Github
Inside the subsequent a page click the “Authorise AWS Connector for GitHub”
Now hit “Install a new app”
Pick the account you want to have it installed in
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.
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.
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”.
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
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? Check this out https://james-turner.medium.com/from-github-to-continuous-deployment-in-5-minutes-7f9c1c7702b1