When you’re working with source control, it’s important to keep your data organized and accessible. One way to do this is to use code commit, a tool that helps you keep your code up-to-date and organized. Code commit lets you add new files and folders to your project, as well as change the contents of existing files. When you commit your changes, CodeCommit will automatically push those changes to the AWS cloud. You can then access those changes from any computer in the world, without having to worry about installing or maintaining a local copy of CodeCommit. To get started with CodeCommit on AWS, first create an account and sign in. Then follow these steps:

  1. Choose a project to work on. In our example, we’ll be working on a web application. To choose a project, click on the “New Project” button at the top of the screen.
  2. Enter a name for your new project and select “AWS.” If you don’t have an AWS account yet, create one now! Once you’ve created your project, click on “Create.”
  3. In the “Project Details” section of the screen, enter some information about your new project: name (for example “WebApplication”), location (for example “US-East-1”), and type (for example web application). You can also enter some notes about your project if you want: for example, how long you plan to keep it open (we plan to keep it open for 3 years). Click on “Create.”
  4. After creating your project, click on its link at the top of the screen so that CodeCommit will show up in its list of projects under “My Projects.”
  5. To start committing changes to your project using CodeCommit on AWS, click on one of the commits in Code Commits under My Projects->Code Commits->My Project->Code Commit History

CodeCommit is AWS’s managed source control solution. It’s a crucial component in AWS’s CodeSuite CI/CD pipeline, which makes it easy to run frequent code builds and deploy application updates programmatically to your EC2 servers or Lambda functions.

What Is CodeCommit?

Really, CodeCommit by itself isn’t fantastic. It works well as a basic source control provider, and you can certainly use it as your primary repository, but it does fall a bit short of the competition—GitHub, GitLab, BitBucket, and others—when it comes to day-to-day usability.

Where CodeCommit shines is its integration with AWS. AWS has a whole continuous development/continuous integration pipeline that they call CodeSuite. It starts with CodeCommit, which simply hosts your source code in the AWS ecosystem. Whenever you’re ready to update, you can send the source over to CodeBuild, which can run all of your automated tests and build your project using build servers it fires up automatically. If the build is successful, you can deploy updates automatically to a fleet of EC2 servers or Lambda functions.

CodeCommit isn’t required to use AWS’s CI/CD pipeline, as CodeBuild supports source control from GitHub, BitBucket, and S3, but it’s so simple to use Git with two remotes that we recommend the following configuration if you want to use CodePipeline:

Continue using your primary source control as normal, alongside Jira and whatever other third-party tools you use to streamline development. On the operational side of things, when you’re ready to release new changes, have the project manager (or any other authorized individual) pull all the changes from the primary repository, switch the remote to CodeCommit, and push all the new commits to AWS. Once CodeCommit is updated, the pipeline can begin from there with all of the new code in CodeCommit.

This way, CodeCommit contains a perfect copy of your project and commit history whenever you’re ready to release, without requiring you to actually use CodeCommit as your primary source control. This also keeps CodeCommit essentially free, as you’re only really using one user, and aren’t making thousands of commits per month. You’re given 50 GB of storage before being charged (enough for most projects without huge binary files) and an unlimited number of repositories. The only charges are $1 per month for each active user beyond the first five, and $1 per month for each 2,000 Git requests beyond the first 10,000. You’re also charged $0.06 per GB per month beyond the free 50.

If you’re using GitHub or BitBucket already, you can instead choose to pull directly from there with a bit of setup. But, if you’re using GitLab (or any other provider), you have to use this two remote setup in order to use CodePipeline (unless you want to manually upload code to S3, a much clunkier solution).

Setting Up an Additional CodeCommit Release Remote

First, you need to create the repository. From the AWS CodeSuite console, navigate over to CodeCommit, select “Repositories” in the sidebar, and click “Create Repository”.

Give it a name, description, any tags you want, and click “Create”.

You’re then brought to the repo home screen, and if you’re signed in with a root account, you’ll be given a fat warning telling you that you cannot configure SSH connections for a root account, and that HTTPS connections are not recommended. You’ll want to set up any connections to CodeCommit on IAM Users, probably the project manager’s existing account. Sign in to that account, or head over to the IAM Console and make a new user specifically for this purpose (with Management Console access):

You’ll want to give access to CodeCommit on the role selection screen.

Keep the IAM Console open, because you need to add your public SSH key here. Click on the user that is being used for CodeCommit access, and under the “Security Credentials” tab, find a button for uploading public SSH keys.

Paste in your machine’s private key, which you can usually find with:

You can add multiple keys here to give multiple machines access to CodeCommit over git. For each key, you’re given an “SSH Key ID”, copy it.

Open up ~/.ssh/config or create it if it doesn’t already exist. Paste in the following configuration, subbing in your key ID:

Make sure the permissions are set to 600:

This ensures git makes a proper connection using the IAM user you set up.

Once that’s out of the way, you should be able to add a new remote as normal. Your primary remote is probably called “origin”. Create a new one called “release”, using the SSH URL CodeCommit gives you:

Then, when you run git push, specify the remote name and branch to which you’re pushing:

You can also set up a separate branch for release deployments, with the upstream set to release by default, but this is the simplest setup and should work fine. Running the previous command updates CodeCommit, provided your local repository is up to date with your primary source control when you run it.