How to continuously deploy a static website in style using GitHub and AWS

  1. You should have an AWS account already setup.
  2. You should have CLI access configured for your account.
  3. Your static website should already be hosted out of AWS S3. If not, check out this link.

Configuring GitHub and AWS Communication

  1. While logged into GitHub, click your profile photo in the top right, then click Settings.
  2. On the left, click Developer settings.
  3. On the left, click Personal access tokens.
  4. Click Generate new token and enter AWSCodePipeline for the name.
  5. For permissions, select repo.
  6. Click Generate token.
  7. Copy the token somewhere so we can use it later.

Creating Our CodePipeline By Hand

  1. Navigate to CodePipeline in the AWS Console.
  2. Click Create Pipeline.
  3. Enter a name for your Pipeline.
  4. Select GitHub as the source provider.
  5. Click Connect to GitHub. This will open a separate window where you sign into your GitHub account. Once signed in, you must grant repo access to AWS CodePipeline. This is the communication link between your GitHub repo and CodePipeline.
  6. Select the repository you want to use in this Pipeline.
  7. Enter master, or your default branch, in the Branch input.
  8. Click Next.
  9. For the Build provider we are going to choose AWS CodeBuild.
  10. Select Create a new build project.
  11. Enter a name for your Build project.
  12. For the Environment image we will use an image provided by AWS CodeBuild.
  13. Select Ubuntu as the operating system.
  14. Select Node.js as the Runtime and nodejs:6.3.1 as the Version.
  15. Leave Build specification as the buildspec.yml option.
  16. In the CodeBuild service role section, we want to create a new service role.
  17. Enter a name for the service role CodeBuild will use.
  18. Leave the rest of the values at their default settings.
  19. Click Save build project and then click Next.
  20. For Deployment provider we want No deployment.
  21. Click Next.

Who likes clicking buttons? Not me.

  • name of our pipeline
  • our GitHub username
  • our GitHub token from earlier
  • the GitHub repository we want to link to our pipeline
  • We create an S3 bucket that will hold the artifacts/outputs from each stage in our pipeline.
  • We need to create an IAM policy that allows CodePipeline to assume a role we create here in our template, codepipeline_role. That role has a policy attached to it, attach_codepipeline_policy. The policy grants access to AWS services that we need to call during an invocation of our pipeline.
  • We configure the resources needed in order for CodeBuild to work as expected. We define an assume role policy that allows CodeBuild to assume a role and access services via the codebuild_policy.
  • We create our actual CodeBuild project, build_project, that runs the build stage of our CodePipeline. Notice here we specify the source to be codepipeline and our buildspec to be buildspec.yml.
  • Your infrastructure definition lives in source control. It can be iterated on as code would be.
  • Your infrastructure is now repeatable. If you need to move it to another AWS region, you can run the template in that region.
  • You can quickly make changes by changing the template and applying updates.

Wait, what did we just do?

Setting up our buildspec file

Triggering our CodePipeline

Bam! We have continuous deployment

Hungry to learn more Amazon Web Services?

👏 If you enjoyed this, don’t forget to offer claps to show your support!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store