Table of contents
The first step is to setup an S3 bucket for your static site, I have 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 tick 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. 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.
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.
Here is another article you might like 😊 "Avoid using target blank if you can"