Boy sitting and watching code

See Practical Ways How To Create and Store Your Source Code in AWS CodeCommit In 5 Minutes


So, you have heard that their is something sweeter than storing your code on Github, especially if you are going to be using the AWS CodePipeline service to manage your deployment and application lifecycle. The AWS CodeCommit is a good option if your used case demands you use AWS service for your end-to-end pipeline.

The AWS CodeCommit is Amazon Web Service fully manage source control service which is capable of hosting private git repositories. Like Github, it is also capable of working with the git client to store your appliation source code directly into a remote repository.

I personally recommend the AWS CodeCommit due to its ease of use and configuration. The good thing is the learning curve is so short it take less than 5 minutes to start using it. Heads-up, if you have used git client in any way, you are good to go with the AWS CodeCommit.

Here in this walkthrough as our custom, we will create an AWS CodeCommit, see how we can authenticate our AWS IAM User with remote AWS CodeCommit repository with our local repository, and demostrate how to push you changes from your local machine into the AWS CodeCommit without any headache.

This walkthrough will be the first in the series of AWS CodePipeline walkthrough. So keep and eye our for the walkthrough on AWS CodeBuild, AWS CodeDeploy and AWS CodePipeline.


To follow along this tutorial, you will need:
An IAM user with the CodeCommit permission
A directory that is locally created
The AWS CodeCommit auth keys (which we will generate later in this tutorial)

Once those are ready, let’s go!!!

CREate the AWS CodeCommit Repository

Let’s head over to the AWS console, type in AWS CodeCommit in the search bar. It will bring you to the CodeCommit window. Click on the Getting Started option, and then Create Repository on the right of the page.

Getting started with AWS CodeCommit repository

You will be asked to name your repository in the next window. Provide a name and a description (the description is optional). Thereafter, click on the orange Create button.

Add a name to your AWS CodeCommit repository

Hey!!! That is all about creating the AWS CodeCommit repository. You should get some information like below once you successfully create the repository. Take note of the clone command which contains the repository address. We will use this address to connect our local repository to our remote AWS CodeCommit repository.

Generate Git Credentials for https

Like your Github Personal Access Token, AWS does not allow the use of your console account password for authenticating for your repository, that is why we need to generate an AWS CodeCommit git credentials for HTTPS authentication. In the next steps, we will generate the CodeCommit credentials that we will use to connect our local repository to the remote repository.

Now, head to your IAM window, click on the Users option to select the specific user you want to generate the credentials for. Then click on the Security Credentials tab under the user.

After that, scroll down to find the HTTPS Git Credentials for AWS CodeCommit option, and click on the Generate Credentials.

Generate AWS CodeCommit Credentials from IAM.

Once you clicked the Generate Credentials button, you will find the information in another window like below. Do not rush to close this window. Use the Download Credentials button to download it to your local system (put it in a safe location on your local machine), thereafter, close the window.

With that piece of information, you will authenticate your AWS CodeCommit with your local repository.

test commit from local repository to remote CodeCommit repository

Once you have your credentials, you can go ahead to add it to the repo and authenticate. However, I choose to go a little futher to show how to create and local repository and add the remote origin from AWS CodeCommimt.

As a test, I have created a empty local directory. $ mkdir testadmin

Then, I change directory into the new directory. $ cd testadmin

And then initialize the directory to contain the .git directory, where I will be adding my AWS CodeCommit remote origin using the $ git init command.

Thereafter, add the repository URL to the repository and check the remote origin again.

$ git remote add origin
$ git remote -v

Add the remote origin for AWS CodeCommit

Once we have confirmed that our repository is okay, we can create a test file and commit it from our local machine to our repository.

$ touch test-file
$ echo "This is a sample text to AWS CodeCommit" >> test-file

Create a sample file for AWS CodeCommit

Thereafter, we will need to set our file for staging and the commit it. First I check the status of the local repository with the git status command, and then proceed with committing the file.

$ git status
$ git add .
$ git commit -m "demo commit"
$ git status

Stage the test file commit for remote AWS CodeCommit repository

Once that is done, we can then push the changes to our remote repository. At the point where you run the git push command, AWS will ask for your credential which was generated earlier. Supply the username and the password you downloaded in previous steps inside the popup window and you will be fine.

$ git push -u origin main

Successfully pushed to AWS CodeCommit repository

Now, let’s head back to our console, you should see the new branch (main) that you push from your local repository inside the AWS CodeCommit now.

Showing the newly push test file and the branch inside AWS CodeCommit

Voila!!! You have successfully create AWS CodeCommit, added it to you local machine, and able to commit your changes securely using the HTTPS credentials from your local machine to your remote AWS repository.






Leave a Reply

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