To create a new CodeCommit version-control repository, go to your AWS console and select CodeCommit under Developer Tools. Click the Create new repository button, enter a unique repository name and a description and click Create repository. Next, you will connect to the repository.
Connect to the CodeCommit Repository
There are a couple of ways to connect to an existing CodeCommit repository. One is via https and the other ssh. We’re going to focus on the connecting via SSH in this post. For additional information, see Connect to an AWS CodeCommit Repository. The instructions in this section are based on CodeCommit Setup from Andrew Puch.
The first thing you’ll do is create an IAM user. You do not need to create a password or access keys at this time. To do this, go to the AWS IAM console, then the Users section and create a new user. Once you’ve created the new user, open a terminal and type the following. NOTE: These instructions are designed for Mac/Linux environments.
cd $HOME/.ssh ssh-keygen
When prompted after typing
ssh-keygen, use a name like
codecommit_rsa and leave all fields blank and just hit enter
Go to IAM, select the user you previously created, click on the Security Credentials tab and click the Upload SSH public key button. Copy the contents of the
codecommit_rsa.pub to the text box in the Upload SSH public key section and save.
Go back to your terminal and type:
touch config chmod 600 config
sudo vim config
The YOUR_SSH_KEY_ID_FROM_IAM variable below is the row value for the SSH Key Id that you created when uploading the public key. You will replace this placeholder and brackets with the value for the SSH Key Id from the Security Credentials tab for the IAM user you’d previously created.
Host git-codecommit.*.amazonaws.com User [YOUR_SSH_KEY_ID_FROM_IAM] IdentityFile ~/.ssh/codecommit_rsa
To verify your SSH connection works, type:
If successful, your results will look something like:
You have successfully authenticated over SSH. You can use Git to interact with AWS CodeCommit. Interactive shells are not supported.Connection to git-codecommit.us-east-1.amazonaws.com closed by remote host. Connection to git-codecommit.us-east-1.amazonaws.com closed.
To clone a local copy of the CodeCommit repo you just created, type something like (your region and/or repo name may be different):
git clone ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/codecommit-demo
You’ll be using this local copy of your CodeCommit repo.