How to use CodeCommit

feature image

What is AWS CodeCommit?

AWS CodeCommit is a version control service hosted by Amazon Web Services that is Git server on AWS.


Why you want to use CodeCommit?

Copy from https://docs.aws.amazon.com/codecommit/latest/userguide/welcome.html

  • Benefit from a fully managed service hosted by AWS.
    • CodeCommit provides high service availability and durability and eliminates the administrative overhead of managing your own hardware and software. There is no hardware to provision and scale and no server software to install, configure, and update.
  • Store your code securely.
    • CodeCommit repositories are encrypted at rest as well as in transit.
  • Work collaboratively on code.
    • CodeCommit repositories support pull requests, where users can review and comment on each other’s code changes before merging them to branches; notifications that automatically send emails to users about pull requests and comments; and more.
  • Easily scale your version control projects.
    • CodeCommit repositories can scale up to meet your development needs. The service can handle repositories with large numbers of files or branches, large file sizes, and lengthy revision histories.
  • Store anything, anytime.
    • CodeCommit has no limit on the size of your repositories or on the file types you can store.
  • Integrate with other AWS and third-party services.
    • CodeCommit keeps your repositories close to your other production resources in the AWS Cloud, which helps increase the speed and frequency of your development lifecycle. It is integrated with IAM and can be used with other AWS services and in parallel with other repositories. For more information, see Product and service integrations with AWS CodeCommit.
  • Easily migrate files from other remote repositories.
    • You can migrate to CodeCommit from any Git-based repository.
  • Use the Git tools you already know.
    • CodeCommit supports Git commands as well as its own AWS CLI commands and APIs.

Setup for HTTPS users using Git credentials

The simplest way to set up connections to AWS CodeCommit repositories is to configure Git credentials for CodeCommit in the IAM console, and then use those credentials for HTTPS connections.

Initial configuration for CodeCommit

  1. Sign in to the AWS Management Console and open the IAM console at https://console.aws.amazon.com/iam/.
  2. In the IAM console, in the navigation pane, choose Users, and then choose the IAM user you want to configure for CodeCommit access.
  3. On the Permissions tab, choose Add Permissions.
  4. In Grant permissions, choose Attach existing policies directly.
  5. From the list of policies, select AWSCodeCommitPowerUser or another managed policy for CodeCommit access.
permission 1
permission 2

Create Git credentials for HTTPS connections to CodeCommit

After you have installed Git, create Git credentials for your IAM user in IAM.

To set up HTTPS Git credentials for CodeCommit

  1. Sign in to the AWS Management Console and open the IAM console at https://console.aws.amazon.com/iam/.
  2. In the IAM console, in the navigation pane, choose Users, and from the list of users, choose your IAM user.
  3. On the user details page, choose the Security Credentials tab, and in HTTPS Git credentials for AWS CodeCommit, choose Generate. generate git credential
  4. Copy the user name and password that IAM generated for you, either by showing, copying, and then pasting this information into a secure file on your local computer, or by choosing Download credentials to download this information as a .CSV file. You need this information to connect to CodeCommit. git credential
  5. After you have saved your credentials, choose Close.

Install Git

Follow the instruction in https://git-scm.com/downloads to install Git in your own notebook.

MacOS

brew install git

Connect to the CodeCommit console and clone the repository

To connect to a CodeCommit repository

  1. Open the CodeCommit console at https://console.aws.amazon.com/codesuite/codecommit/home.
  2. In the region selector, choose the AWS Region where the repository was created. Repositories are specific to an AWS Region.
  3. Find the repository you want to connect to from the list and choose it. Choose Clone URL, and then choose the protocol you want to use when cloning or connecting to the repository. This copies the clone URL.
    • Copy the HTTPS URL if you are using either Git credentials with your IAM user or the credential helper included with the AWS CLI.
    • Copy the HTTPS (GRC) URL if you are using the git-remote-codecommit command on your local computer.
    • Copy the SSH URL if you are using an SSH public/private key pair with your IAM user.
  4. Open a terminal, command line, or Git shell. Run the git clone command with the HTTPS clone URL you copied to clone the repository. For example, to clone a repository named MyDemoRepo to a local repo named my-demo-repo in the US East (Ohio) Region:
git clone https://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo my-demo-repo

The first time you connect, you are prompted for the user name and password for the repository. Depending on the configuration of your local computer, this prompt either originates from a credential management system for the operating system, a credential manager utility for your version of Git (for example, the Git Credential Manager included in Git for Windows), your IDE, or Git itself. Enter the user name and password generated for Git credentials in IAM (the ones you created in Step 3: Create Git credentials for HTTPS connections to CodeCommit). Depending on your operating system and other software, this information might be saved for you in a credential store or credential management utility. If so, you should not be prompted again unless you change the password, inactivate the Git credentials, or delete the Git credentials in IAM.


Clean up resources

Delete all the users/roles/repo.

,