Skip to content

Instantly share code, notes, and snippets.

@mlabieniec
Last active December 23, 2017 17:54
Show Gist options
  • Save mlabieniec/f819b26a61201cbde6cf9dfe27cb2718 to your computer and use it in GitHub Desktop.
Save mlabieniec/f819b26a61201cbde6cf9dfe27cb2718 to your computer and use it in GitHub Desktop.
Connecting to AWS CodeCommit
  1. Goto your AWS IAM Console and create or modify a current IAM user (preferably the one you use to connect with your AWS CLI)

  2. Goto Security Credentials -> Scroll down to SSH keys for AWS CodeCommit

  3. Create a private/public ssh key on your local machine:

    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

  4. Click on "Upload SSH Public Key" and paste in the contents of ~/.ssh/id_rsa.pub into the textarea and save.

  5. Note the Access Key ID that was generated, it will be something like APKA********** this will be used as your User for SSH access

  6. Navigate to the AWS CodeCommit Console and click on your repository (or create one)

  7. Create a ~/.ssh/config file with the following contents (modify for your setup/names):

    Host MyCodeCommit HostName git-codecommit.us-east-1.amazonaws.com User Your-IAM-SSH-Key-ID-Here IdentityFile ~/.ssh/id_rsa

Now you can connect to any repository within your AWS CodeCommit with:

git clone ssh://MyCodeCommit/v1/repos/my-repo-name-here

You can have multiple repositories in the ~/.ssh/config file with different custom "Host" names, just keep the "HostName" value to the appropriate AWS CodeCommit URL and you can access them via

git clone ssh://My-Custom-Name/v1/repos/my-repo

For example (~/.aws/config):

Host SomeRepo
 HostName git-codecommit.us-east-1.amazonaws.com
 User Your-IAM-SSH-Key-ID-Here
 IdentityFile ~/.ssh/id_rsa
 
Host SomeOtherRepo
 HostName git-codecommit.us-east-2.amazonaws.com
 User Your-IAM-SSH-Key-ID-Here
 IdentityFile ~/.ssh/id_rsa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment