Skip to content

Creating an AWS CodeCommit Repository.

For more information on Code Commit, visit

CodeCommit Description

This tutorial will walk through the steps required to create your first CodeCommit Repository, and then make your first commit and push to that new repository.

CodeCommit Pre-Requisites

1.    Active AWS Account:
You will need to have an active AWS account, as this lab will cover setting up an AWS CodeCommit Repository.

2.    IAM User:
You will need an IAM user created with the appropriate permissions (Admin access for this demo). The user should have console access, and access to the CodeCommit service.

IAM User Required:

Code Commit will not allow commits over SSH using the root user.

3.    GIT:

You must have GIT installed on your local workstation. For instructions on how to install GIT for your local workstation, go to the Git site, and follow the appropriate instructions for your platform.

IAM User SSH Key

In order to use Code Commit, you will need to have an IAM user with a configured SSH key to access and push to the repository once it has been created. Perform the following steps in order to ensure that the IAM user that you will use, has an SSH key configured for use with the Code Commit service.

1.    Open IAM console:
First, logged in as an IAM user, we need to upload an SSH Key that will allow us to push commits to our codecommit repository once it's created. In order to do this go to the IAM console from the list of Services in the main navigational menu drop list. From the top left side of the navigational menu bar, click on the Services menu, and then choose IAM by either navigating to the Security, Identity, and Compliance section of the listed services, or by typing the first few letters of the service name in the search box, and then choosing it from the filtered list.


2.    Select User Account:
From the right side menu in the IAM console, select the Users section, and then click on the user that will be creating and committing to the repository.

IAM Users

3.    Upload SSH Key:

Next, from the IAM user profile, scroll toward the bottom of the profile, and click the button labeled: Upload SSH public key

IAM User Profile

In the pop up dialog box, copy your SSH key from your workstation and paste it into the dialog box, and click the Upload SSH public key button.

IAM Upload SSHKeys

4.    Verify SSH Key:

Once completed, you will return back to your user profile. Again, scroll down to the SSH Key section, and verify that your key is now present in your profile.

IAM Verify SSHKeys

Create the Repository

Because we will use CodeCommit as the GIT repository that will store our project code, we must first create a repository where our code will live using the CodeCommit Service.

1.    Open CodeCommit Console:
From the top left side of the navigational menu bar, click on the Services menu, and then choose CodeCommit by either navigating to the Security, Identity, and Compliance section of the listed services, or by typing the first few letters of the service name in the search box, and then choosing it from the filtered list.


2.    Create Repository:
From within the CodeCommit console screen, Click the Create repository button at the top, in order to create our first repository.

Create Repository

3.    Name the Repository:

In the dialog box, choose a name for the repository, and then type out a description. Once you have entered the repository details properly, then click the Create repository button.

CodeCommit Repository Details

4.    Email Notifications:
The next screen will allow us to set up any email notifications that we would like. CodeCommit can integrate with SNS in order to send these notifications. If you have a pre-existing SNS topic that you would like to use to send notifications on commit events such as comments, commits, or merge actions, then choose the topic now. You also have the option of creating a new SNS topic directly. To keep this tutorial simple, we are not going to set up notifiations at this time, and instead will just hit the Skip button to proceed.

CodeCommit Repository Notifications

Configure Repository Connections

1.    Get Connection Details:
Once the repository has been created, a dialog box on the left side of the console will appear showing you how to configure your workstation to connect to the new repository. Choose your connection type (SSH) and operating system, and then copy the SSH config details from the Steps to clone your repository section.

CodeCommit Connection Details

CodeCommit Connection Config

IAM User Required:

If you are logged in as the root user, you will NOT be able to get SSH connection details. It is strongly advised that you log out of the root user account, and log in with a valid IAM user that has the appropriate permissions to allow the user to interact with the CodeCommit Service

CodeCommit Connection Root

2.    Configure Workstation:
Next, we need to go to our workstation, and open our SSH config file. Once the file has been opened, simply paste the connection config into the file and save the file.

vim ~/.ssh/config

CodeCommit Workstation Config


3.    Create Project Directory:
Next, if we don't have an existing project, then we need to make a local directory on our local workstation where our GIT project can be constructed. Follow the steps for your platform to create a directory named SimpleAPI on our workstation and open a command shell, to navigate to the newly created directory.

mkdir -p ~/Documents/Projects/SimpleAPI
cd ~/Documents/Projects/SimpleAPI

4.    Initialize GIT:
Once in the new directory, we will want to initialize the directory to start tracking file changes that will be included in our git commits. In order to initialize a directory, simply type the following command.


git init 

Command Console Output:

Initialized empty Git repository in /Users/awsdocs/Documents/Projects/SimpleAPI/.git/

5.    Add Git Repository:
Now that we have GIT initialized, now we need to tell the local git repository what remote GIT repository to push to. We do this with the git remote add command, using the URL that we copied to our clipboard previously.

Remote Repo Designation:

The word origin between our command and the repository URL is the arbitrary name of the upstream remote repository. We name the remote repository locally, in the event that we want to add multiple upstream repositories to the local repository.


git remote add origin ssh://

Repository URL:

The repository URL can be found on the CodeCommit repository connection details screen. If you have closed the console view already, you can find this information by clicking on your repository and then clicking either the Clone URL button, or the Connect button to show full connection details.

CodeCommit URL

You can verify that the remote repository URL is set properly by looking at all remotely configured remote repositories for your local repository:


git remote -v

Command Console Output:

origin ssh:// (fetch)
origin ssh:// (push)

Create the Code Base

Now that we have Git and our repositories all set up, we are ready to construct a code base, that will be pushed to the new repository.

1.    Create API Python File:
Using the editor of your choice, create a file named and paste the following code content into the file.

# *******************************************************************
# Bottle Example API
# Authors/Maintainers: Rich Nason (
# *******************************************************************

# Required Modules:
# =================

# Install Requirements via PIP
from bottle import Bottle, HTTPResponse  # Web server

# Bottle Parameters:
# ===================

VERSION = '0.0.1'     # API Version
BOTTLEIP = ''  # The IP that Bottle will listen on to serve the API
BOTTLEPORT = '80'   # The TCP port that bottle will use to serve the API

# Setup the Bottle WebServer Instance:
# ====================================

APP = Bottle(__name__)

# Index Route
@APP.route('/', method=['OPTIONS', 'GET'])
def index():
        resp_msg = "All systems reporting go for launch!!"
        body = {'version': VERSION, 'message': resp_msg}
        response = HTTPResponse(status=200, body=body)
        return response
    except Exception as err:
        body = {'version': VERSION, 'message': err}
        response = HTTPResponse(status=400, body=body)
        return response

# Start the Web Server
# =====================

if __name__ == '__main__':
        SERVER =, port=BOTTLEPORT, debug=True)
    except KeyboardInterrupt:

Commit the Codes!

Now that we have the directory, repositories and code file all set, its time to make our first commit.

1.    Commit:
From the command line, simply use the git add --all command to add all files in the current directory to the commit, and then use git commit -m "Message" command to make our commit.


git add --all; git commit -m "Initial Code Commit"

Command Console Output:

[master (root-commit) d79b1f8] Initial Code Commit
 1 files changed, 54 insertions(+)
 create mode 100644

2.    Push your Commit:
Last we need to simply push our commit(s) (Multiple commits can be pushed together). We do this simply by using git push command.

GIT Command:

when using the git push command, we need to supply 2 parameters.

  • The name of the remote repository that we configured when we added the remote repository to the local repository.
  • The branch name that we want to push to.
By default when we create a project we only have the master branch, however as the repository grows multiple branches can exist within the same repository.


git push origin master

Command Console Output:

Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 4.14 KiB | 0 bytes/s, done.
Total 5 (delta 0), reused 0 (delta 0)
To ssh://
 * [new branch]      master -> master

3.    Verify, and Do a Little Dance!:

Once the push has completed, you can log back into CodeCommit, click the repository, and you should see your new commit. Congratulations, you have successfully pushed your first commit to Gitlab!

Commit Verification

CodeCommit Conclusion

In this walk through, we configured a CodeCommit repository, we configured the repository and workstation for proper access, we created a code base, and we successfully pushed that code base to our new repository. Using CodeCommit to track code changes for multiple repositories and multiple branches in each repository is simple and easy. The same steps and procedures that apply to other SCM's such as Gitlab, BitBucket, Github, etc.. will also apply to CodeCommit.

CodeCommit Additional Resources

No Additional Resources.

CodeCommit Site/Information References

No Additional References.