How to clone AWS CodeCommit repository from EC2 instance

August 13, 2016 2 Min

CodeCommit is a git service in AWS, you can own the private repository just a small fee, if you are personal or small group will be not charged any fee in some way.

Well, I will deploy my application from CodeCommit to EC2, below is my way. First I created a repository in CodeCommit.

Before create a new EC2 instance, add a new IAM role.

Now you will see this screen, click select button in Amazon EC2.

Input CodeCommit in filter and click AWSCodeCommitReadOnly.

Now review the IAM role, if no any problem then click Create Role.

OK, let’s check the role, you will see something like below.

Now I can create a new EC2 instance and assign a role, this step is important, do not forgot!

Well done, I can start setting my EC2 instance, first thing is check AWS CLI version, CodeCommit only working with AWS CLI 1.7.38 and later, type aws –version in terminal and check the version. For Debian will needs upgrade AWS CLI version, just follow steps.

$ sudo apt-get purge aws
$ sudo apt-get install python-pip
$ sudo pip install awscli

When done, setting git config, just two commands.

git config --global credential.helper '!aws codecommit credential-helper [email protected]'
git config --global credential.UseHttpPath true

Now clone git repository from CodeCommit.

[email protected]:~$ git clone
Cloning into '0x427567-Test'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.

For now, my EC2 can direct clone repository from CodeCommit and do not need setting AWS CLI credential, let me know if you have any question, thanks!