How to setup HTTPS users to upload code into codecommit using git credential
Tags: awscodecommit, https, gitcredential
Published: 2023-08-19 12:09:33

CodeCommit is a fully managed source control service that makes it easy to host secure and highly scalable private Git repositories. CodeCommit eliminates the need to operate your own source control system or worry about scaling its infrastructure. You can use CodeCommit to securely store anything from source code to binaries, and it works seamlessly with your existing Git tools.

![code commit](https://cdn-images-1.medium.com/max/2000/1*XojsNE1Pfmz8V9eBfqgB1Q.png)

### Prerequisites:

1. **Install git**: To install Git, we recommend websites such as [Git Downloads](http://git-scm.com/downloads) .

2. **Create IAM user and give permission:** If you don’t know how to create IAM user and give permission for aws services, then please check this **[reference](https://medium.com/p/42644f61fea5/)** post. You need to follow the steps from **1–9**.

### **Create Git credentials for HTTPS connection to CodeCommit**:

- If you have an IAM user, please go that “**user**” page from left menu and select the checkbox of the user where you want to configure **“HTTPS Git credentials for AWS CodeCommit”**. Then select ***“Security credentials”*** tab of this page.

![security credential](https://cdn-images-1.medium.com/max/2800/0*r8O-w1NumHWGCGbH)

- Then click on ***“Generate credentials”*** button.

![Generate credential](https://cdn-images-1.medium.com/max/2800/0*lBFIs5kxlj4Utc54)

- It will generate username and password like the following image. Download the credentials for further use. This credential will be used in the **gitlab mirroring repository** section.

![Download credential](https://cdn-images-1.medium.com/max/2800/0*4e5SVPX-ALF7RiyX)

### **Create CodeCommit repository and link it to gitlab code:**

- Search CodeCommit in aws console and click on it. You will find an option to create repository like following image:

![Search CodeCommit](https://cdn-images-1.medium.com/max/2800/0*JfoMasfWxvm2yg_i)

- Then click on “**Create repository**” button and fill up the following fields:

![Create repository](https://cdn-images-1.medium.com/max/2732/0*Y-_GOz5T8xs-Vvhe)

- Here I am giving **tutorial-app** as repository name. You have to give your repository name here and click on **“Create”** button.

- Then you will see newly created repository into your repositories list like following:

![Repository](https://cdn-images-1.medium.com/max/2800/0*rW4RIRflHDZmme0j)

- Then click on the radio button of ***“tutorial-app”*** repository (your repository name) and then from that page you will get following ***“clone url”*** option and select that button and choose ***“clone HTTPS”***:

![Clone URL](https://cdn-images-1.medium.com/max/5608/1*2zsI3OqjyU6_29HMsq2aZw.png)

- When you click on “**clone HTTPS**” button, you will see a link is copied like following image:

![Clone HTTPS](https://cdn-images-1.medium.com/max/5756/1*ft8LhCo9PJ-iqJYO89D5lg.png)

- You have to use this link into gitlab.

### Setup mirroring gitlab code to CodeCommit:

- First browse the link [https://about.gitlab.com/](https://about.gitlab.com/) and click on the **Login** button and then login into the system by giving our gitlab credentials.

- Then search your gitlab project and click on that project. Here I will use my previously created “**tutorial-backend**” project.

- Then select ***Settings*** -> ***Repository*** from ***tutorial-backend:***

![Settings](https://cdn-images-1.medium.com/max/2000/1*JpmkkhVQLXY_Q9kfrGxwVA.jpeg)

- Then click on ***“Expand”*** from ***“Mirroring repositories”*** like following image:

![Expand](https://cdn-images-1.medium.com/max/2800/0*9_G7_3wQ_Re3Diah)

- Then take the previously copied url (**step no 6** from **Setup mirroring gitlab code to CodeCommit** section) and paste it like following image:

![Copied URL](https://cdn-images-1.medium.com/max/2800/0*6P-KjK1x7wulbX_C)

- Then you have to use the IAM ***codeCommit username*** after ***“https:// ”*** and then ***“@”*** sign after codeCommit username like following image and also copy the ***IAM codecommit password*** into the password field. Then click on the **“Mirror repository”** button. 
(Get your codecommit username and password from **step no 3** from **Create Git credentials for HTTPS connection to CodeCommit** section)

![Gitcommit username password](https://cdn-images-1.medium.com/max/2800/0*eeB1A-fDFC5BelIH)

- After that click on “***sync***” icon in gitlab mirroring section like following:

![Sync](https://cdn-images-1.medium.com/max/2800/1*JrESLwhoz2wM-JOALQMZXw.png)

- After that please go to **CodeCommit** page from **aws console** and see that your code is synced to codeCommit like following image:

![CodeCommit page](https://cdn-images-1.medium.com/max/2800/0*i473z4ujMz_MzNkW)