How to Build a CI/CD Pipeline using GitHub and AWS Ecosystem

Sanchit
7 min readAug 12, 2023

--

CI/CD stands for Continuous Integration and Continuous Deployment. It is a process that automates the building, testing, and deployment of software. This helps to ensure that software is always in a releasable state and that any changes made to the code are quickly and reliably deployed to production.

A CI/CD pipeline typically consists of the following steps:

  1. Source control: The code is stored in a source control repository, such as GitHub or GitLab.
  2. Build: The code is built into a deployable artifact, such as a Docker image or a JAR file.
  3. Test: The artifact is tested to ensure that it works as expected.
  4. Deploy: The artifact is deployed to a production environment.

By automating these steps, CI/CD can help to improve the quality and reliability of software. It can also help to speed up the development process by reducing the amount of manual work required.

Here is a simple example of a CI/CD pipeline principle:

  1. A developer makes a change to the code in a source control repository.
  2. A CI/CD tool, such as GitHub Actions, automatically builds the code and runs tests.
  3. If the tests pass, the CI/CD tool deploys the code to a staging environment.
  4. A QA engineer tests the code in the staging environment.
  5. If the QA engineer approves the code, the CI/CD tool deploys the code to production.

Tech Used

  1. GitHub: A widely used web platform for version control and collaboration, enabling seamless code management and team collaboration.
  2. Amazon S3: A scalable cloud storage service by AWS, allowing you to store and retrieve data, host websites, and manage files securely.
  3. AWS CodeCommit: A managed source control service that provides secure and scalable hosting for private Git repositories.
  4. AWS CodeBuild: A fully managed CI/CD service that compiles, tests, and packages code, automating the build process and ensuring code quality.
  5. AWS CodePipeline: An automated CI/CD service that orchestrates and visualizes the software delivery process, seamlessly integrating various stages.
  6. AWS CodeDeploy: An automated deployment service that simplifies code releases to various computing environments, ensuring consistent and reliable updates.
Architecture

Step 01. Create S3 bucket to store build files

Before you start hosting your static website, you’ll need to make an S3 bucket. Here’s what you do:

  1. Go to the AWS Management Console and open the Amazon S3 section at this link: https://console.aws.amazon.com/s3/
  2. Click on “Create bucket”
  3. Give your bucket a unique name
  4. Choose the place (Region) where you want the bucket to be
  5. In the part that talks about stopping the public from seeing your stuff, uncheck the box that says “Block all public access”
  6. Keep the rest of the settings as they are, and make the bucket by clicking “Create”

Step 2. Using S3 Bucket for Hosting

  1. Click on the bucket you made, then go to the “Properties” part
  2. Scroll down and click “edit” where it says “Static website hosting”
  3. Pick the “Enable” choice for Static website hosting
  4. Put in the names of your index.html and error.html files
  5. Keep the other stuff that’s already there and press “Save changes” to finish.

Step 3. Grant public read access to the bucket (Important)

To make your S3 bucket accessible and prepare for the next step, follow these instructions:

  1. Open your S3 bucket settings and find the “Permissions” section.
  2. Look for “Bucket Policy” and click on it.
  3. In the “Bucket Policy” section, you’ll see an option called “Policy Generator.” This tool helps you create a policy that defines who can access your bucket and how. Here’s what you do:
  4. Inside the “Policy Generator,” find the specific action called “GetObject.” This action is about getting files from your bucket.
  5. Create a policy by selecting this action and generating a code for it. You will see that AWS will autogenerate some code for you. This process is very important, therefore make sure to perform this activity with high precision, else your bucket won’t be able to be consumed by other AWS applications or services
  6. Now, go back to the Permissions tab, and paste below code code into the policy section.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Statement1",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:PutObjectAcl",
"s3:DeleteObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::serverless-react-1/*",
"arn:aws:s3:::serverless-react-1"
]
}
]
}

If you’re following along with a project, make sure to change a part of the code (ARN) to match the name of your bucket.

And don’t forget to add “/*” after your bucket name, this will set up every file available in the bucket for public access

7. Click on Save button available on the console

Bucket set up for public access

As you can see from the image above, the bucket created is having public visibility now

Step 4. Using AWS CodePipeline with GitHub

  1. Go to the AWS console and search for CodePipeline.
  2. Click on Create Pipeline and give your pipeline a name. Then, click Next.
Pipeline Creation

3. To connect CodePipeline to GitHub, follow these steps:

4. Once GitHub is connected, go back to CodePipeline and do the following:

  • Under “Source provider,” choose “GitHub (Version 2).”
  • In the dropdown menu, select the GitHub connection that you just created.
  • Select the name of the repository that holds your project’s source code.
  • Select the branch name that you want to use for the pipeline.
  • Click Next.
Prompt to create a connection

5. For building, choose AWS CodeBuild and click Create Project. Follow the instructions given on the page to create a CodeBuild project.

6. In the Deploy section, select the deployment target. This could be an Amazon EC2 instance, an Amazon ECS service, or an Amazon S3 bucket.

Click Create to create the CI/CD pipeline.

Once the CI/CD pipeline is created, it will automatically trigger a build whenever there are changes to the source code in your GitHub repository. The build artifacts will then be deployed to the deployment target (S3 Bucket) that you have specified.

Step 5. AWS CodeBuild

AWS CodeBuild is a powerful tool that takes care of building and testing software smoothly. It works like a silent partner, managing all the technical details so developers can focus on writing great code. It easily connects with popular code storage places like GitHub, making teamwork a breeze. No matter how big your project gets, CodeBuild can handle it — like a dependable teammate that steps up when needed. And it keeps clear records of what it’s doing, helping you understand and fix any issues.

Build Stage

In essence, AWS CodeBuild is your reliable companion in the coding world, ensuring your software is built and tested flawlessly.

  1. Enter all the required information on this page in accordance with the S3 bucket that we created before
AWS CodeBuild

2. Click on ‘Create Build’ project button and then navigate to AWS Pipeline page

Step 6. CodeDeploy

In the deployment step, opt for your S3 bucket, just as illustrated in the image provided

AWS CodePipeline Deployment Stage

Review the information provided

Review Screen of AWS

Click on ‘Create Pipeline’

Pipeline Created

After a while you will see the above message on the screen, make sure the pipeline runs successfully for all the steps created above

Visit the Deployed Website

To proceed, begin by opening a new tab in your web browser and navigate to the AWS S3 section.

Once there, find your designated S3 bucket and click on its name to access its settings. Within the bucket, locate and click on the ‘Properties’ option. As you scroll down the page, you’ll come across the ‘Static website hosting’ section.

S3 Bucket

Here, you’ll find a link labeled as the Bucket website endpoint. This link acts as a virtual pathway to your hosted content, providing a seamless way to explore your online creation, and you can click on that link to access your webpage

Successful Deployment

You can test your CI CD pipeline by making changes to your code files and committing them to GitHub repository

In conclusion, we’ve embarked on a comprehensive journey to establish a robust CI/CD pipeline using the powerful tools provided by AWS. By seamlessly integrating GitHub, AWS CodeBuild, AWS CodePipeline, and Amazon S3, we’ve harnessed the ability to automate and streamline every stage of our software development process

If you want to learn how to make a Serverless AWS Backend Architecture in Seven Easy Steps, Please follow my other article

Follow Sanchit on LinkedIn For More

--

--