CI/CD pipeline on AWS (Part 1) - CodeCommit

In the upcoming 4 blogs, we will be making a CI/CD pipeline on AWS with these tools: CodeCommit, CodeBuild, CodeDeploy, and CodePipeline.

In today's learning, let's deal with AWS CodeCommit.

In this project, we will learn how to set up a code repository on AWS CodeCommit and clone it to our local machine. We will also explore the process of adding a new file from the local machine, committing the changes to the local branch, and pushing the changes to the CodeCommit repository. Additionally, we will cover working with multiple branches and pushing local files to different branches. By following these steps, you will gain a solid understanding of using CodeCommit for version control in your projects.

Table of Contents:

  1. Task 1: Set up a code repository on CodeCommit and clone it on your local

    1.1 Generate Git credentials
    1.2 Set up a code repository on CodeCommit
    1.3 Clone repository from CodeCommit

  2. Task 2: Add a new file from local and commit to your local branch. Push the local changes to the CodeCommit repository
    2.1 Add a new file from local and commit to your local branch
    2.2 Push the local changes to the CodeCommit repository

  3. Working with multiple branches and pushing local files
    3.1 Creating a new branch and making changes
    3.2 Creating a pull request and merging changes
    3.3 Verifying the merged changes

What is CodeCommit?

AWS CodeCommit is a version control service hosted by Amazon Web Services that you can use to privately store and manage assets (such as documents, source code, and binary files) in the cloud.

Similar alternatives are GitHub (well-known and widely used), and Azure Repos (a Feature of Azure DevOps).

Why CodeCommit?

With CodeCommit, you can:

  • Benefit from a fully managed service hosted by AWS.

  • Store your code securely.

  • Work collaboratively on code.

  • Easily scale your version control projects.

  • Store anything, anytime.

  • Integrate with other AWS and third-party services.

  • Easily migrate files from other remote repositories.

  • Use the Git tools you already know.

How does CodeCommit work?

  1. Use the AWS CLI or the CodeCommit console to create a CodeCommit repository.

  2. From your development machine, use Git to run the git clone, specifying the name of the CodeCommit repository. This creates a local repo that connects to the CodeCommit repository.

  3. Use the local repo on your development machine to modify (add, edit, and delete) files, and then run git add to stage the modified files locally. Run git commit to commit the files locally, and then run git push to send the files to the CodeCommit repository.

  4. Download changes from other users. Run git pull to synchronize the files in the CodeCommit repository with your local repo. This ensures you're working with the latest version of the files.

Tasks

Task 1: Set up a code repository on CodeCommit and clone it on your local.

Pre-requisites:

  • You should have an AWS account.

  • Install and configure the AWS Command Line Interface (CLI) on your local machine.

Step 1: Generate Git credentials

Go to IAM Service > Click on "Users" in the left navigation pane > Create a New User > Checkbox for Provide user access to the AWS Management Console - optional > Select I want to create an IAM user and give password > Click on Next.

In the next step > Click on Attach Policies Directly > Select the policy AWSCodeCommitFullAccess > Click on Create User.

Download the .csv file since this is the only time you can view and download this password.

Open the User you created > Go to the Security Credentials tab > Scroll down to HTTPS Git credentials for AWS CodeCommit > Select Generate Credentials > Download credentials and click on Close.

These are the Git credentials for accessing CodeCommit.

Step 2: Set up a code repository on CodeCommit.

Go to the AWS Management Console and navigate to the CodeCommit service and click on "Create repository".

The repository is successfully created now.

Step 3: Clone repository from CodeCommit.

Go to your CodeCommit repository in the AWS Management Console. Click on the "Clone URL" and then click on the 'Clone HTTPS' button to copy the repository URL.

In the terminal, navigate to the directory where you want to clone the repository.

Run the following command to clone the repository

#git clone <https>
git clone https://git-codecommit.us-east-1.amazonaws.com/v1/repos/demo-app

Enter the username and password that we have downloaded earlier.

Wow!! You have created an empty repository in AWS CodeCommit and cloned it to your local.

Task 2: Add a new file from local and commit to your local branch. Push the local changes to the CodeCommit repository.

Step 1: Add a new file from local and commit to your local branch.

Using the following command, push the changes from your local to the CodeCommit repository.

Verify that the files are pushed into the CodeCommit repository.

In the CodeCommit Repository > Repositories > Code.

Yahooo!! You have pushed your local files to the CodeCommit Repository.

If you want to work with multiple branches and push your local files, you can easily do so without any issues.

Let's create a new branch called "dev" and make some changes to the index file. Afterwards, we can push the file from the "dev" branch.

Go to the "Repository" section and navigate to the "Branches" tab. Check to see if there are two branches: "master" and "dev" (which we recently created).

Next, select the "dev" branch and click the "Create pull request" button.

Enter the title name and review the changes. Finally, click the "Create pull request" button again to proceed.

Now, click the "Changes" button to review the modified parts. If everything looks good, click the "Merge" button to merge the changes.

Now, choose the merge strategy you prefer. I have selected the "Fast Forward Merge" option. Click the "Merge Pull request" button to proceed.

Once the pull request is merged, check the index file to ensure that the merge was successful.

By completing this project, you have successfully set up a code repository on AWS CodeCommit, cloned it to your local machine, and learned how to add and commit files to the repository. You have also gained the knowledge to work with multiple branches and push local files to different branches. AWS CodeCommit provides a secure and scalable solution for managing your code repositories in the AWS environment. With this newfound knowledge, you can confidently utilize CodeCommit for version control in your software development projects.

Thank you for reading this blog. If you found this blog helpful, please like, share, and follow me for more blog posts like this in the future.

— Happy Learning !!!

Let’s connect !!!

Linkedin

Medium

Github

Mail