GIT is a well-known source control tool, widely used by programmers around the world. One of the biggest advantages over others source control tools is its simplicity. DevOps methodology is highly tied to GIT because it assumes that most of the configuration is based on the code.

One of the most popular web-based git repository in the world is GitHub. However, in this tutorial, I’d like to leverage the AWS service called CodeCommit. It’s available for everyone with AWS account, its free for first 5 users and very cheap for other ones. This will become our base for any future projects. Before you start to set your GIT environment, please make sure you have the following things:

  • AWS account (it’s free for the first 1y)
  • GIT client installed on your PC
  • Code editor (it can be anything from Windows notepad or VIM to more sophisticated tools like Microsoft Visual Studio Code - which is personally my best code editor)

Let’s get started. Go to the AWS Console, and open CloudCommit service (you can find it in the Developers Tools section). The main screen may vary depends on whether you have used this service before or not. Click on Create repository and fill in the necessary fields (repository name and description).

repository setup

You will get the warning about the user setup. We will go through the steps soon. Next, the wizard will prompt you for the creation of email notification. For the purpose of this course, we will skip this step. Now your first repository is ready to use. AWS will automatically show you some off the things which need to be configured in order to access this repository.

access config

Next step is to create the users with appropriate permissions to access this repository. Go to IAM service, create new group GitUsers and attach IAMSelfManageServiceSpecificCredentials, IAMReadOnlyAccess, and AWSCodeCommitFullAccess policies to this group. Next, create some sample user and make sure you created Programmatic access for him. Add this user to the previously created group. Make sure you noted the Access Key ID and Secret access key. Below is an example of such a user:

access config

Now it’s time to configure your PC environment to work with the GIT. In this example, I’ll show you how to configure Ubuntu Linux. If you’re using a different environment, please refer this documentation Setting Up for AWS CodeCommit

From the bash console, run the following commands to install and configure access to AWS account + GIT.

$ sudo apt-get install git awscli -y
$ aws configure
AWS Access Key ID []: #YOUR AWS ACCESS ID#
AWS Secret Access Key []: #YOUR AWS SECRET ACCESS ID#
Default region name []: #YOUR DEFAULT AWS REGION, E.G. eu-west-1#
Default output format []: #LEAVE EMPTY#

Now configure your GIT to use CodeCommit repository

$ git config --global credential.helper '!aws codecommit credential-helper $@'
$ git config --global credential.UseHttpPath true
$ git config --global user.email "your@email.com"
$ git config --global user.name "Your Username"

After that you should be able to clone your previously configured repository. Then add some changes, commit and upload.

$ git clone https://git-codecommit.eu-west-1.amazonaws.com/v1/repos/mynewrepository
$ cd mynewrepository
$ echo 'Hello World' > hello.txt
$ git add .
$ git commit -m 'My first commit'
$ git push origin master

You can now log in to CodeCommit console and see a newly added file.

This is all for now. I hope you understand how to configure remote GIT repository in AWS using CodeCommit. It will be our base for future projects, like creating the terraform template to create our AWS resources from the code.

I hope you enjoyed the reading :)