Static Website Deployment on a S3 Bucket with GitHub and CodePipeline

Static Website Deployment on a S3 Bucket with GitHub and CodePipeline

I have a static website I want to periodically change but I manage the code on GitHub, how can I host this on a S3 bucket and ensure the content is synced? This isn’t actually as daunting as it may sound, getting this to sync with AWS S3 is relatively easy with CodePipeline. Like with many AWS services, there is a small cost.

I will be reusing one of the S3 buckets from a previous tutorial for this, specifically tutorial-001-sj.

  1. Sign into the AWS Console
  2. Under “Find Services” type in “CodePipeline” and select CodePipeline.
    AWS Management Console CodePipeline
  3. Note: Ensure you are in the right region, the first time I did this I wanted to pull my hair out as I kept getting “Cannot convert undefined or null to object codepipeline” it turned out when I selected the correct region and everything matched it went away. Click on “Create Pipeline”.
    AWS Create Pipeline
  4. Under “Pipeline name”, give it a name. I went with “tutorial-001-sj”. For the role name, I left this as default “AWSCodePipelineServiceRole-us-west-1-tutorial-001-sj”. Then click “Next”.
    Choose Pipeline Settings
  5. Under the “Source Provider”, select “GitHub”. Then select the repository and branch you would like to upload the commits from. Then click “Next”. Note: If you see a button that says “Connect to Github” you will need to connect your AWS and GitHub account to continue.
    CodePipeline Add Source Stage
  6. Under “Add build stage”, click “Skip build stage”. It will come up with a warning, click on “Skip”.
    CodePipeline Add Build Stage
  7. Under “Add deploy stage”, select the “Deploy provider”, it should be set to “Amazon S3”. Set the region that corresponds with your S3 bucket, in my case this was “EU (Frankfurt)”. Then select the bucket, ensure that “Extract file before deploy” is checked, then click “Next”.
    CodePipeline Add Deploy Stage
  8. Review and ensure everything looks good, then create “Create Pipeline”.
    Pipeline Validation
  9. Once the pipeline is created it will take you to a page like the below. Access your S3 bucket and check to see that the index.html file or files in the repo are there.
    Pipeline Preview
  10. Go to GitHub and make a minor change to one of the files. In my case the changes were updated instantly.
    Website with Updated Changes

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.