Setting2 Up CICD Pipeline with AWS CodeCommit and S3 Hosting

Simplified Guide to Setting Up CI/CD Pipeline with AWS CodeCommit and S3 Hosting | ExamNative

2
4 minutes, 29 seconds Read

Welcome to our comprehensive guide on setting up a Continuous Integration and Continuous Deployment (CI/CD) pipeline using AWS CodeCommit for version control and Amazon S3 for website hosting. This blog will walk you through each step, from creating the necessary IAM roles to deploying your application in different environments using S3 buckets. By the end of this blog, you’ll be equipped with the knowledge to efficiently manage your web application’s lifecycle on AWS.

Introduction

In today’s fast-paced development world, automating the build, test, and deployment processes is crucial for efficient and error-free application delivery. AWS offers a suite of services to facilitate this, including CodeCommit for version control, S3 for hosting static websites, and various CI/CD tools for automation.

Prerequisites

Before we dive into the steps, ensure you have the following:

  • An active AWS account with permissions to create IAM roles, S3 buckets, CodeCommit repositories, and CodePipeline pipelines.
  • Basic understanding of IAM (Identity and Access Management).
  • A public repository on GitHub with the sample code.

Step 1: Create Required IAM user and required credentials.

  1. Navigate to the IAM Management Console in your AWS Dashboard and attached required Permissions or AdministratorAccess
  2. Go to User’s Security credentials Tab and Generate Access keys required for AWS CLI login.
    Access keys for AWS CLI
    HTTPS Git credentials for AWS CodeCommit. for Git Login
    .
  3. AWS CodeCommit will automatically create AWS Service Role for CodeCommit.

Step 2: Create S3 Buckets for Test and Production Environments

  1. Open the S3 Management Console: From your AWS Dashboard, go to the S3 service.
  2. Create New Bucket: Click “Create bucket”.
    Name your bucket (must be unique globally), select the region, and keep the default settings. Repeat this step to create two buckets: one for the test environment and another for production.
    Buckets Name: “examnative-test and examnative-prod”.

Step 3: Enable S3 Bucket for Hosting Public Website

  1. Select Your Bucket: From the S3 dashboard, click on the bucket you created for the test environment.
  2. Enable Static Website Hosting: Navigate to the “Properties” tab and click on “Static website hosting”. Choose “Use this bucket to host a website” and enter the index document (e.g., index.html). Repeat for the production bucket.
  3. Set Bucket Policy: Go to the “Permissions” tab and edit the bucket policy to allow public access to your website content, and make sure to update your bucket name in given policy.
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::your-bucket-name/*"
        }
    ]
}

Step 4: Set Up AWS CodeCommit and Import Code from GitHub

Download Application Code to Local System

  1. Initialize your local folder with git using git init.
  2. Clone your GitHub repository using git clone <GitHub_Repo_URL>. ExamNative/UseCases (github.com)
  3. Navigate into your repository directory.

Upload Code to AWS CodeCommit

  1. Set up Git credentials for CodeCommit in the IAM dashboard under your user’s “Security credentials” tab. (IAM -> User -> Security Credentials -> HTTPS Git credentials for AWS CodeCommit -> Generate credentials -> Download credentials)
  2. Change the remote repository URL to your CodeCommit repository’s HTTPS URL using
    git remote set-url origin <CodeCommit_Repo_URL>.
    # git remote add https://git-codecommit.us-east-1.amazonaws.com/v1/repos/examnative-codecommit-repo
    # git remote set-url origin https://git-codecommit.us-east-1.amazonaws.com/v1/repos/examnative-codecommit-repo
  3. Push your code to CodeCommit using,
    git push --set-upstream origin main.

Step 5: Set Up AWS CI/CD Pipeline

Source Stage: AWS CodeCommit

Create a Pipeline: Go to the AWS CodePipeline dashboard, click “Create pipeline”, name your pipeline, with default setup.

And Next Add storage stage: Set the source provider as CodeCommit, select your repository and the branch.

Skip Build Phase

When configuring your pipeline, you can skip the build phase by selecting “Skip build stage” since we are deploying a static website.

Deploy Application on S3 Test Environment

Add Deploy Stage: Choose “Amazon S3” as the deploy provider, select the test environment bucket, and enable “Extract file before deploy”.

Review all the settings and click on Create Pipeline. The pipeline has been created and automatically executed for our test environment.
Your test environment setup is ready, test your website by hitting on test bucket website URL.
From here we will start set-up for Prod Environment.

Manual Intervention and SNS Configuration

Note: SNS Topic and Subscribe with Email (Already Done)

  1. Now edit the current pipeline (Developer Tools -> CodePipeline ->Pipelines -> pipeline -> Edit).
  2. Add Manual Approval Stage: Before the production deployment, add a manual approval stage, action and configure SNS to notify you when approval is needed.

Deploy Application to Production Environment

Add one more stage after Manual Approval Stage: Deployment-Prod.

Deployment-Prod (New Stage) -> Add Action Group ->Edit Action

Enter the required details for the production environment, ensuring you select the production bucket this time. And we also provide the URL for Review (URL of Test Environment)

As Our test environment is up and running and we want to execute same code to Prod Environment.
We need to click button “Release changes.” Pipeline will wait for Approver for Approval.

After successfully reviewed and approved, it will start deploying to Production environment.

Conclusion

By following these steps, you’ve successfully automated the deployment of your web application with AWS CI/CD tools, leveraging CodeCommit for version control and S3 for hosting. This setup not only simplifies your development workflow but also ensures a reliable and efficient delivery process. Happy coding!

author

Kartik Kocher

👋 Namaste! I'm Kartik Kocher, a Senior Cloud DevOps Engineer with over 8 years of experience in AWS cloud and DevOps. I'm passionate about delivering innovative cloud solutions, specializing in CI/CD pipelines, infrastructure automation, containerization, and cloud security. I've worked across various sectors, bringing efficiency through new products and services. Proficient in Jenkins, GitHub, AWS CodeBuild, and CodeDeploy for CI/CD pipelines, and adept at Kubernetes deployments on AWS EKS. Skilled in Terraform for infrastructure as code (IaC) practices. Security-focused with expertise in IAM roles, security groups, and compliance checks. Certified as an AWS Certified DevOps Engineer - Professional and AWS Certified Solutions Architect. I've led projects like migrating on-premises workloads to AWS and Azure, optimizing costs, and implementing CI/CD pipelines. Committed to following AWS best practices and contributing to the tech community through knowledge sharing and blogging. Reach out at me@kartikkocher.com or visit my website https://www.kartikkocher.com for collaboration or to connect. Tech enthusiast. Cloud explorer. Innovator. Let's connect and explore the endless possibilities in the cloud domain together! 🚀

Similar Posts

2 Comments

Leave a Reply

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

X