This articles describes how to connect to a CodeCommit repository that you have already created.
- Create CodeCommit repository
- Using a SSH Connection on Linux/MacOS
1. Create CodeCommit repository
If you haven’t created your CodeCommit repository yet, go to AWS CodeCommit and create a repository.
Enter a repository name and optionally a description and click “Create”. Once you have your repo, you will be able to connect using HTTPS or SSH:
2. Using a SSH Connection on Linux/MacOS
2.1 Creating SSH public keys
First we will need to create our SSH public keys, so open up terminal on your machine and type:
This will allow you to configure ssh keys for your user. Type the following commands in order to generate the keys with the correct information for the subsequent steps making sure to replace the paths with your own machine paths:
Enter file in which to save the key (/home/user-name/.ssh/id_rsa): /home/your-user-name/.ssh/codecommit_rsa Enter passphrase (empty for no passphrase): Some Pass Phrase Enter same passphrase again: Some Pass Phrase again
This should generate your keys and save them into the locations you specified on your machine. Next, type the following code in order to copy the key for pasting into your IAM user in AWS IAM:
Go to the IAM Management Console, click on your user, and then go to Security credentials. Once there, click on “Upload SSH public key” and paste in the value that you copied above. That’s it for creating and updating your user with a public SSH key.
2.2 Edit local SSH Config
After your public SSH key is uploaded, we need to update the config file in the local ~/.ssh folder
sudo vim ~/.ssh/config
Place the following code inside the config:
Host git-codecommit.*.amazonaws.com User IAM-SSH-KEY-ID-HERE IdentityFile ~/.ssh/Your-Private-Key-File-Name-Here
Once you have saved the file, make sure it has the right permissions by running the following command in the ~/.ssh directory..
chmod 600 config
Finally, we can clone the CodeCommit repo to your local machine by copying the URL in the top-right dropdown “Clone URL” and selecting “Clone SSH”:
git clone the-ssh-url-that-you-copied
3. Using a HTTPS Connection
The steps to connect using a https connection are similar to the SSH connection. Instead of uploading a public SSH key from your local machine, we need to go to the “HTTPS Git credentials for AWS CodeCommit” section of the IAM user console and click “Generate credentials”. A csv will generate with your HTTPS credentials.
After this, you can copy the HTTPS url and run the following command:
git clone the-https-url-that-you-copied