AWS CodeCommit

A quick guide to using AWS CodeCommit using the AWS CLI.

Getting help

aws codecommit help

Enough for getting around!

Generate SSH credentials

Required for cloning a repository:

ssh-keygen -f ~/.ssh/codecommit_rsa

Then, set this up with CodeCommit:

  1. Sign to the AWS Console.

  2. Open your IAM Users page, and select the user you wish to give CodeCommit access to with this SSH key (or create a new one and use it for the rest of the steps).

  3. Click Add permissions, then Attach existing policies directly.

  4. Use the Filter policies search box to search for "codecommit". Choose the checkbox near either AWSCodeCommitFullAccess (to allow repository deletion) or AWSCodeCommitPowerUser to allow write permission.

  5. Click Next: Review, then Add permissions.

  6. Switch to the Security Credentials tab for your IAM user, and click the Upload SSH public key button.

  7. Copy the contents of ~/.ssh/codecommit_rsa.pub and paste it into the Upload SSH public key dialog.

  8. Create (or edit) ~/.ssh/config, and add the following contents:

    Host git-codecommit.*.amazonaws.com
      User REPLACEME
      IdentityFile ~/.ssh/codecommit_rsa
    

    You'll fill in that sample REPLACEME value next...

  9. Back in the AWS console, copy the SSH key ID from your IAM user's Summary page, and paste it in place of REPLACEME in the ~/.ssh/config file.

  10. Save and close the file.

  11. Go to your command-line, and change ~/.ssh/config's permissions to 600 (AKA -rw-------):

    chmod 600 ~/.ssh/config
    

You should now be able to use the SSH key to access your CodeCommit repositories!

For more info

Creating a repository

aws codecommit create-repository --repository-name repo_name

Creates a repository using repo_name as the repository name, and prints its info (the same info you get when running aws codecommit get-repository).

After creating a repository, you can clone it to add files to your new, blank repository.

Listing your repositories

aws codecommit list-repositories

Prints a listing of the repositories for your account. For each, it reports the repositoryName and repositoryId.

Getting info about a repository

aws codecommit get-repository --repository-name repositoryName

Lists the metadata associated with the repository, including:

  • accountId
  • repositoryId
  • repositoryName
  • repositoryDescription
  • defaultBranch
  • lastModifieddate
  • creationDate
  • cloneUrlSsh
  • Arn

The cloneUrlSsh field, in particular, is important when you want to clone the repository in order to work with its files.

Cloning a repository

Once you've set up your SSH credentials correctly, you can clone the repository by:

  1. Using the aws codecommit get-repository command to get the cloneUrlSsh value for cloning the repository.

  2. Using the cloneUrlSsh value to clone your repository like any other git repository:

    git clone cloneUrlSsh
    

Once you've cloned the repository, you can use normal git commands to work with your local copy, or git pull and git push to interact with your codecommit repository.