Automate deployment to AWS S3 using Github actions

The first step is to setup an S3 bucket for your static site, you can read a different article on how to do that. In other to enable deployment from Github to S3 you should also have the source code hosted on Github first.

Once you have the above out of the way, we can go ahead and automate deployment from Github to our S3 bucket.

Setting up a Code Pipeline

Search for the Code pipeline service using the AWS search bar. This is the service that we will be using to set all this up.


Next click on the Create pipeline button, then fill out the pipeline details:

  • Set the Pipeline name to whatever for example the domain of your website for easy identification.
  • If it's your first setup check the New service role box
  • For the Advanced settings section choose the defaults to use your existing S3 location and default keys.


Connecting to Github

On clicking next you will land on a new form where you can now connect to your Github account. The dropdown provides a list of possible connections. There are currently two types of Github connections:

  • Github (Version 1): This is the old way of connecting to Github via Oauth, this is not the option we want.
  • Github (Version 2): This will allow us to connect and setup Github actions as our deployment option and this is the option we want.

Select Github (Version 2) as your Source provider. Then click on Connect to Github to finally connect to your Github account.

After that, you should be able to select the Repository name and Branch name you will like to deploy from. You can leave the remaining settings as is.


Skipping the build process

For now, we will skip the build process. Later you can do this using the AWS CodeBuild service. skip-build

Add deploy stage

Next we setup the S3 bucket we will like to deploy to.

  • From the dropdown select Amazon S3
  • Then the Bucket you will like to deploy to.
  • Skip the S3 object key text field and check the Extract file before deploy option.

Click on Next double check your entries on the next screen then click on Create pipeline.


And that's it! From this point on when you make changes in your Github repo, they will be deployed onto your S3 bucket