How To Access An AWS CodeCommit Repository Remotely

How To Access An AWS CodeCommit Repository Remotely

How To Access An AWS CodeCommit Repository Remotely

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed how to create an AWS CodeCommit repository using AWS CLI.

https://cloudaffaire.com/how-to-create-an-aws-codecommit-repository/

In this blog post, we will discuss on how to access an AWS CodeCommit repository remotely. There are several ways you can configure access to your CodeCommit repository. You can simply access and manage your CodeCommit repository from the AWS directly. If you intend to manage your CodeCommit repository from your local system then you can configure either SSH access or HTTP access. In this blog post, we will cover both SSH and HTTPS option.

Note: There are some additional methods of accessing your CodeCommit repository like HTTP with git-remote-codecommit which is required when you are using any identity provider or temporary credentials, but form simplicity we will cover the most common HTTPS and SSH methods.

How To Access An AWS CodeCommit Repository Remotely:

Requirements:

AWS CLI installed and configured. You can follow the below blog post to install and configure AWS CLI.

https://cloudaffaire.com/how-to-install-aws-cli/

https://cloudaffaire.com/how-to-configure-aws-cli/

Git installed and configured.

https://cloudaffaire.com/category/devops/git/

How To Configure HTTPS Connection To AWS CodeCommit Repository:

Step 1: (Optional) Create an IAM user to access CodeCommit.

If you have followed the above blog post to configure your AWS CLI then you already have full access and can skip this step. Else create a new IAM user with programmatic access and attach AWSCodeCommitPowerUser IAM policy to the user.

How To Access An AWS CodeCommit Repository Remotely

Once the user created, copy the IAM user Access key and Secret key and configure AWS CLI using the same set of keys.

How To Access An AWS CodeCommit Repository Remotely

Step 2: Install Git in your local system.

https://www.atlassian.com/git/tutorials/install-git

Step 3: Create Git credentials for the IAM user to connect to CodeCommit.

Login to AWS console and navigate to IAM

Select the IAM user and navigate to the ‘Security Credentials’ tab and click on ‘Generate Credentials’

How To Access An AWS CodeCommit Repository Remotely

Copy the username and password, we will need that in the next step. You can also download the credential into your local system by clicking on the download link.

Step 4: Get your CodeCommit repository HTTPS clone URL.

Login to the AWS console and navigate to CodeCommit.

Select your repository and click ‘HTTPS’ as shown below figure. The URL will be copied to your clipboard, save it for the next step.

How To Access An AWS CodeCommit Repository Remotely

Or, if you are following my previous blog post.

Step 5: Configure Git credentials and clone the CodeCommit repository in your local system.

Provide the git username and password (retrieved in step 3) when prompted. If everything worked fine then a new directory will be created which will serve as your local repository for your AWS CodeCommit remote repository.

Step 6: (Optional) Configure git username and email.

Now you are ready to perform any git operation on your AWS CodeCommit repository using your local system. Next, we are going to perform the same setup using SSH.

How To Configure SSH Connection To AWS CodeCommit Repository:

Step 1: (Optional) Create an IAM user to access CodeCommit.

If you have followed the above blog post to configure your AWS CLI then you already have full access and can skip this step. Else create a new IAM user with programmatic access and attach AWSCodeCommitPowerUser IAM policy to the user.

How To Access An AWS CodeCommit Repository Remotely

Once the user created, copy the IAM user Access key and Secret key and configure AWS CLI using the same set of keys.

Step 2: Install Git in your local system.

https://www.atlassian.com/git/tutorials/install-git

Step 3: Create your SSH keys in your local system.

Copy the key which will be required in the next step.

Step 4: Configure SSH key for IAM user.

Login to AWS console and navigate to IAM

Select the IAM user and navigate to the ‘Security Credentials’ tab and click on ‘Upload SSH public key’. Paste the public key (retrieved in the previous step) and click ‘Upload SSH public key’

How To Access An AWS CodeCommit Repository Remotely

Step 5: Copy the key id once uploaded.

How To Access An AWS CodeCommit Repository Remotely

Step 6: Set your local SSH configuration file

Step 7: Get your CodeCommit repository HTTPS clone URL.

Login to the AWS console and navigate to CodeCommit.

Select your repository and click ‘SSH’ as shown in the below figure. The URL will be copied to your clipboard, save it for the next step.

How To Access An AWS CodeCommit Repository Remotely

Or, if you are following my previous blog post.

Step 5: Configure Git credentials and clone CodeCommit repository in your local system.

Note: If you get an error, you can try with the Key-Id that you got in step 5.

git clone ssh://<SSH_KEY_ID>@git-codecommit.<AWS_REGION>.amazonaws.com/v1/repos/<REPOSITORY_NAME>

Step 6: (Optional) Configure git username and email.

Now you are ready to perform any git operation on your AWS CodeCommit repository using your local system.

Hope you have enjoyed this blog post. To get more details on AWS CodeCommit, please refer below AWS documentation

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

CodeCommit is a Git-based version control system and you need to have a basic understanding of Git in order to work with CodeCommit. You can follow the below link to get a basic understanding of Git.

https://cloudaffaire.com/category/devops/git/

 

Leave a Reply

Close Menu