Integrate AWS Cloud9 with AWS CodeCommit - AWS CodeCommit

Integrate AWS Cloud9 with AWS CodeCommit

You can use AWS Cloud9 to make code changes in a CodeCommit repository. AWS Cloud9 contains a collection of tools that you can use to write code and build, run, test, debug, and release software. You can clone existing repositories, create repositories, commit and push code changes to a repository, and more, all from your AWS Cloud9 EC2 development environment. The AWS Cloud9 EC2 development environment is generally preconfigured with the AWS CLI, an Amazon EC2 role, and Git, so in most cases, you can run a few simple commands and start interacting with your repository.

To use AWS Cloud9 with CodeCommit, you need the following:

Step 1: Create an AWS Cloud9 development environment

AWS Cloud9 hosts your development environment on an Amazon EC2 instance. This is the easiest way to integrate, because you can use the AWS managed temporary credentials for the instance to connect to your CodeCommit repository. If you want to use your own server instead, see the AWS Cloud9 User Guide.

To create an AWS Cloud9 environment
  1. Sign in to AWS as the IAM user you've configured and open the AWS Cloud9 console.

  2. In the AWS Cloud9 console, choose Create environment.

  3. In Step 1: Name environment, enter a name and optional description for the environment, and then choose Next step.

  4. In Step 2: Configure Settings, configure your environment as follows:

    • In Environment type, choose Create a new instance for environment (EC2).

    • In Instance type, choose the appropriate instance type for your development environment. For example, if you're just exploring the service, you might choose the default of t2.micro. If you intend to use this environment for development work, choose a larger instance type.

    • Accept the other default settings unless you have reasons to choose otherwise (for example, your organization uses a specific VPC, or your Amazon Web Services account does not have any VPCs configured), and then choose Next step.

  5. In Step 3: Review, review your settings. Choose Previous step if you want to make any changes. If not, choose Create environment.

    Creating an environment and connecting to it for the first time takes several minutes. If it seems to take an unusally long time, see Troubleshooting in the AWS Cloud9 User Guide.

  6. After you are connected to your environment, check to see if Git is already installed and is a supported version by running the git --version command in the terminal window.

    If Git is not installed, or if it is not a supported version, install a supported version. CodeCommit supports Git versions 1.7.9 and later. Git version 2.28 supports configuring the branch name for initial commits. We recommend using a recent version of Git. To install Git, we recommend websites such as Git Downloads.


    Depending on the operating system of your environment, you might be able to use the yum command with the sudo option to install updates, including Git. For example, an administrative command sequence might resemble the following three commands:

    sudo yum -y update sudo yum -y install git git --version

  7. Configure a user name and email to be associated with your Git commits by running the git config command. For example:

    git config --global "Mary Major" git config --global

Step 2: Configure the AWS CLI credential helper on your AWS Cloud9 EC2 development environment

After you've created an AWS Cloud9 environment, you can configure the AWS CLI credential helper to manage the credentials for connections to your CodeCommit repository. The AWS Cloud9 development environment comes with AWS managed temporary credentials that are associated with your IAM user. You use these credentials with the AWS CLI credential helper.

  1. Open the terminal window and run the following command to verify that the AWS CLI is installed:

    aws --version

    If successful, this command returns the currently installed version of the AWS CLI. To upgrade an older version of the AWS CLI to the latest version, see Installing the AWS Command Line Interface.

  2. At the terminal, run the following commands to configure the AWS CLI credential helper for HTTPS connections:

    git config --global credential.helper '!aws codecommit credential-helper $@' git config --global credential.UseHttpPath true

    The credential helper uses the default Amazon EC2 instance role for your development environment. If you intend to use the development environment to connect to repositories that are not hosted in CodeCommit, either configure SSH connections to those repositories, or configure a local .gitconfig file to use an alternative credential management system when connecting to those other repositories. For more information, see Git Tools - Credential Storage on the Git website.

Step 3: Clone a CodeCommit repository into your AWS Cloud9 EC2 development environment

After you've configured the AWS CLI credential helper, you can clone your CodeCommit repository onto it. Then you can start working with the code.

  1. In the terminal, run the git clone command, specifying the HTTPS clone URL of the repository you want to clone. For example, if you want to clone a repository named MyDemoRepo in the US East (Ohio) Region, you would enter:

    git clone

    You can find the Clone URL for your repository in the CodeCommit console by choosing Clone URL.

  2. When the cloning is complete, in the side navigation, expand the folder for your repository, and choose the file you want to open for editing. Alternatively, choose File and then choose New File to create a file.

  3. When you have finished editing or creating files, in the terminal window, change directories to your cloned repository and then commit and push your changes. For example, if you added a new file named

    cd MyDemoRepo git commit -a git commit -m "Added a new file with some code improvements" git push

Next steps

For more information, see the AWS Cloud9 User Guide and CodeCommit sample for AWS Cloud9. For more information about using Git with CodeCommit, see Getting started with Git and AWS CodeCommit.