AWS CodePipeline with GitHub Releases

Geo Nicolaidis
4 min readDec 9, 2020
Photo by Yancy Min on Unsplash

Backstory

After a long time of talking and planning about code pipeline automations amongst our dev team, we have finally made the jump into CI/CD and automated code pipelines this summer. Since we were already heavily using AWS, we decided to try whatever they had to offer in terms of automating and deploying software and see where things would go from there.

The plan was to use Amazon CodePipeline, Amazon CodeBuild, Amazon CodeDeploy and AWS ChatOps with Slack for easy creation and monitoring of the pipelines. The first thing I noticed while building the very first pipeline was the lack of options when it comes to GitHub automation triggers. My development team has been using GitHub’s Releases to package and ship code to production when a new feature is ready but the only option as a trigger out of the box in CodePipeline was “Push” events on a specific git branch like “staging” or “production”. With time pushing down on us to move fast, we have made the decision to change the way we worked until now and start using specific protected branches to release our code to our different environments. The project was in general successful and all of our code releases were migrated into using automated pipelines to deliver our new features to our servers. Success!? Well, almost!

A few months have passed since the completion of the project and our “new” process still felt “wrong” to the team and the lack of trigger options by Amazon felt “unacceptable” to me. With that in mind, I started looking around in older documentations and other online resources and I have finally found a solution to our “headache”.

As it turns out, Amazon CodePipeline does support different types of triggers but they require a bit of a manual work on our end to make it happen. So without any further details, let’s jump into a fast “How To” step by step guide and hopefully by the end of this article you will be able to replicate the changes in your own environments.

Amazon CodePipeline Changes

This guide assumes that you already have the latest version of AWS CLI installed on your machine and you have the right permissions to do perform the changes needed. Also, the pipeline we have in place still uses github v1 as the connection driver and github v2 will not work with this guide.

*** Please use a test pipeline while experimenting with this guide because there is a real chance to damage your production work if you make a mistake. ***

aws codepipeline list-webhooks

The above command will list all of your current webhooks that you have in place. Locate the one you would like to change and copy it somewhere handy, you will use it in the next step.

Create a json file on your local machine and open it up for editing.

Paste the code above in your file and fill out the name, targetPipeline, targetAction, and SecretToken based on the information you copied earlier from your webhook. Before moving further, please pay attention to the “filters” section. The jsonPath and matchEquals are being changed to track changes in releases (published) instead of branch. This is the main reason for the entire operation.

Save the file and execute the following command after you changed <PIPELINE_REGION> to match your region.

aws codepipeline put-webhook --cli-input-json file://filename.json /
--region "<PIPELINE_REGION>"

Before we can give our changes a test run, we will need to update one more thing in GitHub but before you move further, run the first command again to verify the that the changes took place.

aws codepipeline list-webhooks

GitHub Changes

  • Under your GitHub repository, go to settings and from the left vertical menu select webhooks.
  • Find the webhook you would like to change and press “edit”.
  • Find “Which events would you like to trigger this webhook?” and select “Let me select individual events”.
  • Uncheck everything currently selected and select only “Releases”.
  • Press “Update Webhook” to finish your setup.

Here is how it should look like after your changes:

This is it! You have now updated your Amazon CodePipeline to work with Releases as a webhook trigger instead of Branch Pushes.

To test it out I recommend to have Amazon CodePipeline open while you create a new release in GitHub so you can see the automation at work. In case you are having issues with the automation, please make sure you copied the correct information from your aws webhook list and that you edited the correct GitHub project! 😳

Thank you for reading through my article! Feel free to drop me a line, follow me, and show your support by liking this article if you found it useful.

--

--

Geo Nicolaidis

AWS Certified Solutions Architect — Lifelong Student