GitHub Actions logo

Unleashing the Power of the Cloud (AWS): The Epic Journey of the Cloud Resume Challenge-
Part 3: GitHub Actions — CI-CD through Github for the win!

Steve Murimi
6 min readJul 25, 2023

--

AWS Cloud resume challenge.

What is Github?

Personally I consider Github to be a wild and open playground filled with possibilities to work with a vast array of tools and collaborate without borders.

However, GitHub describe themselves as: “GitHub is where over 100 million developers shape the future of software, together. Contribute to the open source community, manage your Git repositories, review code like a pro, track bugs and features, power your CI/CD and DevOps workflows, and secure code before you commit it.”

In coming up with this definition, I was pleasantly pleased to discover that they have an active job board, furthermore, they have a generous offering for students to gain full access and experiment to their hearts content through their Student developer pack. I wish I had found out about this earlier but there is still the possibility of working at a company that has the enterprise subscription.

What is a Github action?

Github describe it as: “GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want.”

It enables countinuous integration and deployment of code by enabling the user to set before hand the criteria needed for certain actions to be taken. We will enable github actions by creating a github repo and linking it to our S3 bucket. At present, to modify the website files, we have to log in to the AWS console and work on our files while on the server, this is neither secure nor tenable, it would be better to make our changes on a github repo and then synchronise the changes to the bucket.

For this illustration, it is assumed that you already have a working github account and that you still have your website files ready locally.

First we will head over to Github and create a new repo.

NB: It is good practice to include a README file for all your repositories.

Once the repo is created, Github will provide you with some commands specific to your repository to get you up and running faster.

To hasten the process, you can simply select all your local files and drag and drop them onto the repo through your browser, once uploaded, you will see your files.

To set the local repo to automatically synchronise with the remote repo on Github, we will follow the set up instructions that were given earlier. The first step is to initialise the local repo. Using a command line tool, navigate to the local location of your website files and initialise the folder by typing ‘git init’ as shown below:

Next we will add the appropriate links to the remote repo by running ‘git remote add origin’ as shown below:

Once you follow the setup steps, add your files so that github can synchronise the tracked changes, it will compare the local files to the remote files. ‘Git add .’ adds all the local files, however, it is possible to specify your files by replacing the fullstop with the specific file name.

Now you can commit your work with a meaningful commit message perhaps better than my feeble attempt, hehe!

To avoid conflicts with the remote repo, it is advisable to ‘pull’ the remote changes locally before pushing your local changes to github.

When this is done, we can then perform a ‘push’.

The steps outlined above are shortcuts, the best way to proceed would be to integrate the instructions provided by Github as evidenced by the instructions received when the repo was created.

Setup Github secrets.

We will now provide Github with credentials to access our S3 bucket. We need the region, bucket name and access key, and secret access key.

On Github, navigate to settings > Secrets and variables then Actions:

Create each item and paste the relevant key for example region will be AWS_REGION and inside it will be our region eg ‘us-west-2’. All the keys must be exactly as provided by AWS. Below is an example of setting up the secret to the S3 bucket:

Setup Github workflows.

In our website project folder, create a folder named ‘workflows’ and within it create a file with the extension ‘*.yml’; it will contain the github workflow.

My files are stored in a folder named website, hence my file named ‘front-end-cicd.yml’ is configured as:

name: Upload Website #name the function as you wish

on:
push:
branches:
- master

jobs:
deploy:
runs-on: ubuntu-latest #Input the appropriate OS
steps:
- uses: actions/checkout@master
- uses: jakejarvis/s3-sync-action@master
with:
args: --follow-symlinks --delete
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
AWS_REGION: us-east-1 #input the region your project is hosted in
AWS_S3_GRANT_WRITE: 'arn:aws:iam::652XXXXXXXXXXX:user/steve-cloud-resume-challenge-s3'
#Replace the arn above with your arn from your S3 bucket console.

NB: To get write access to the bucket, you may need to create a role or a user and attach them to the S3 bucket as the resource. The arn can then be specified in the file as shown above.

Next, assuming all the settings have been correctly saved, edit your website files locally, push the code to github then navigate to the actions tab to check if your github action is working correctly. Success looks like the image below and can further be evidenced by accessing your website URL and seeing your deployed changes.

Now you can take a much deserved break and later on continue experimenting with Github actions, for example it is possible to:
a) Synchronise specific files and folders,
b) Commit to different branches such as prod and dev,
c) Deploy resources to the live website according to branch name,
d) Create a team on Github and create an approval pipeline for items to move from one branch to another ie dev to prod etc.

Celebrate!

If your actions are working thus far, here’s a hearty congratulations and a clarion call to keep going. If you are stuck, just keep at it, after all, repetition creates muscle memory.

Github actions is extremely powerful and can be the strongest arsenal to only those who are worthy! Cheers

Photo by Christine Jou on Unsplash

Join me next time as I embark on Unleashing the Power of the Cloud (AWS): The Epic Journey of the Cloud Resume Challenge-
Part 4: Slaying DynamoDB and API Gateway. The Cloud Resume Challenge continues.

References:

  1. AWS.plainenglish
  2. Github action to S3 Bucket
  3. Configure AWS credentials
  4. Configure AWS credentials
  5. GitHub Action to S3 sync Bucket — My best pick

Project breakdown:

Unleashing the Power of the Cloud (AWS): The Epic Journey of the Cloud Resume Challenge — Part 1: S3 static website hosting.

Unleashing the Power of the Cloud (AWS): The Epic Journey of the Cloud Resume Challenge-
Part 2: Conquering Cloudfront — Harnessing the Forces of Global Content Delivery.

--

--