Integrate Amazon Cloud9 with Amazon CodeCommit - Amazon CodeCommit
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Integrate Amazon Cloud9 with Amazon CodeCommit

You can use Amazon Cloud9 to make code changes in a CodeCommit repository. Amazon 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 Amazon Cloud9 EC2 development environment. The Amazon Cloud9 EC2 development environment is generally preconfigured with the Amazon 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 Amazon Cloud9 with CodeCommit, you need the following:

Step 1: Create an Amazon Cloud9 development environment

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

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

  2. In the Amazon 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 Amazon 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.

    Tip

    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 user.name "Mary Major" git config --global user.email mary.major@example.com

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

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

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

    aws --version

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

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

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

    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 Amazon Cloud9 EC2 development environment

After you've configured the Amazon 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 https://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo
    Tip

    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 MyFile.py:

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

Next steps

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