Connect to AWS CodeCommit From Visual Studio Code

Jinath Premaratne
5 min readJun 18, 2021

In this article I am going to demonstrate how to create an AWS CodeCommit repository on AWS and push your code from Visual Studio Code(VS code) so it will act as your version control system on AWS.
AWS CodeCommit is a version control service, which is hosted and fully managed by Amazon, where it can be used to host Git​-based repositories(documents, binary files, source code).

Setup

In order to follow the steps in this article, you need to have below installed on your computer.

  1. Microsoft Visual Studio Code (free)
  2. GIT (free)

Once you download and install VS code, you need to open VS code and configure GIT. In order to do that, open VS code and click on Terminal > New Terminal and set a GIT user and email.

git config — global user.name “Your Name”
git config — global user.email test@example.com

To check if GIT installed correctly type “git — version” and VS will show the version.

Version Info

Now lets quickly add a sample ASP.NET CORE web app by selecting an empty folder from file menu. Then on the VS terminal window, type “dotnet new webapp” and hit enter to install the new ASP.NET CORE web app. Once installed, you will see sample files on the VS explore.

Sample files

Adding AWS CodeCommit Repository and User

Now let’s setup the AWS CodeCommit repository. Go to AWS management console > Service > Developer Tools >CodeCommit then click on Create Repository, and give a repository name and description and click on Create.

Create Repository

Next we need to create a user on AWS so that VS code can user that user credentials to push the code to AWS. Go to services > Identity and Access Management (IAM) > Users. Click on Add user and give a User name and set the other options as below. You can set your own password or use the auto generated one. Click next.

Add User -1

In the Set permission screen, select the “Attach existing policies directly” tab and select “AWSCodeCommitPowerUser” policy and click next.

Add user 2

Adding Tags is an optional step and you can skip if you want. Next you can Review the policy and click on Create user to create the user on AWS.

Now again navigate to services > Identity and Access Management (IAM) > Users and click on the new user we created. Click on the Security Credentials tab and click on “Generate Credentials” button under HTTPS Git credentials for AWS CodeCommit section. Download the credential file, we need this to connect from VS code.

HTTPS Git credentials for AWS CodeCommit section

As of now we have the CodeCommit repository and a AWS user in order to connect from VS code. Now lets go back to VS code and configure the connection.

Configure Visual Studio Code and GIT

In VS code we have to initialize the local GIT repository, in order to do that type “Git init” in the terminal window. Now we have local GIT repository in the root folder.

Now we will add the files to the repository. Type “git add — all” to add all the files to the Master branch.

Next you have to commit the code the local GIT repository. In the terminal window type “git commit -m “Your comment”” with your commit comment. Now our files have been committed to the Master branch of our local repository. If you type “Git status” it will show that all the files are committed.

In order to connect with our remote AWS repository, lets get the repository URL. Go to AWS management console > Service > Developer Tools >CodeCommit and click on the repository we created before and click on the HTTPS to copy the clone URL

Copy Clone URL

Now in VS code terminal window add below to connect to the remote repository

git remote add origin [Copied URL from AWS]

Eg:- git remote add origin https://git-codecommit.us-east-1.amazonaws.com/v1/repos/vscode

Last step would be pushing the files to the Master branch of the Origin. Type “git push — set-upstream origin master” on the terminal window. This will give you a popup asking for the credentials. Open the download credential file we downloaded before and type the User name and Password in the popup.

Credential Window

After adding the credentials, you will see the files getting uploaded to the remote repository. Now if you go back to the AWS CodeCommit repository we created, you will see our files updated to the Master branch.

CodeCommit

Conclusion

In the article I demonstrated how you can use AWS CodeCommit as a version control system and how to connect to it using Visual Studio Code. In the next article we will see how can we integrate CodeCommit with AWS CodePipeline to have fully managed CI/CD service on AWS.

--

--