Before you begin configuring AWS CodeCommit, make sure you have the following:
Prerequisites:
- An AWS Account (https://aws.amazon.com/)
- The AWS CLI installed and configured (https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
- Git installed on your local machine (https://git-scm.com/))
Now, let's dive into the step-by-step process:
Step 1: Create a repository in AWS CodeCommit
Start by logging into your AWS Management Console and navigating to the CodeCommit service. Click on "Create repository" and provide a name for your repository. Then, simply click on "Create repository" to proceed.
- Navigate to the AWS Management Console and open the CodeCommit console: https://console.aws.amazon.com/codesuite/codecommit/home
- Click on "Create repository."
- Enter a descriptive name for your repository in the "Repository name" field.
- Click "Create repository" to finalize the creation process.
Step 2: Set up IAM user for AWS CodeCommit
To access your repository, you'll need to create an IAM user with the necessary permissions. Go to the IAM service in your AWS Management Console. From the navigation pane, select "Users" and click on "Add user." Choose a username and select "Programmatic access." Proceed to the permissions step and attach the "AWSCodeCommitPowerUser" policy. Complete the setup and download the user's credentials.
- Go to the IAM console in the AWS Management Console: https://console.aws.amazon.com/iam/home
- From the navigation pane, select "Users" followed by "Add user."
- Assign a unique name to the user in the "User name" field.
- Choose "Programmatic access" for access type.
- Click "Next: Permissions" to proceed.
- Select "Attach existing policies directly" and search for "AWSCodeCommitPowerUser" in the search bar.
- Choose the "AWSCodeCommitPowerUser" policy to grant the necessary permissions.
- Click through "Next: Tags" and "Next: Review" to reach the final step.
- Click "Create user" to complete the process.
- Download the user credentials as a CSV file for later use.
Step 3: Configure AWS CLI
-
Open your terminal and run the following command to configure the AWS CLI
aws configure -
Enter your access key ID, secret access key, default region, and desired output format when prompted.
Step 4: Set up SSH Key
For secure access to your repository, you'll need to generate an SSH key pair.
-
In your terminal, navigate to your SSH directory and generate a key pair using the following command:
cd ~/.ssh ssh-keygen -t rsa -b 4096 -
Press Enter to save the key at the default location (~/.ssh/) and optionally provide a name (e.g., codecommit_rsa).
-
Enter a passphrase for additional security (optional).
-
To copy the public key to your clipboard, run:
cat ~/.ssh/codecommit_rsa.pub -
Now, let's upload the public key to your IAM user:
- Go back to the IAM console (https://console.aws.amazon.com/iam/home).
- Select "Users" from the navigation pane and choose the IAM user you created earlier.
- Click on the "Security credentials" tab.
- Select "Upload SSH public key."
- Paste the copied public key into the "SSH public key" field and click "Upload SSH public key."
- Note down the SSH key ID displayed for later use.
-
Configure your SSH client to utilize the key when connecting to CodeCommit:
-
Open your SSH configuration file using a text editor:
vi ~/.ssh/config -
Add the following configuration to the file, replacing
<SSH key ID>with the previously noted ID and<region>with your AWS region:Host git-codecommit.<region>.amazonaws.com User <SSH key ID> IdentityFile ~/.ssh/codecommit_rsa -
Ensure the SSH configuration file has the correct permissions:
chmod 600 ~/.ssh/config
-
Step 5: Clone the repository
Finally, clone your repository using the git clone command. Replace <region> with your AWS region and <repository-name> with the name of your repository. Run the command in your terminal:
git clone ssh://git-codecommit.<region>.amazonaws.com/v1/repos/<repository-name>By following these steps, you've successfully configured AWS CodeCommit and established a secure connection using SSH keys. Now you can start collaborating on your code projects using Git commands

