DEV Community

Pyae Thu Aung
Pyae Thu Aung

Posted on

How to Add Existing Project to AWS CodeCommit

1. Add Required Permission to User

Attach AWSCodeCommitFullAccess permission to user. If current user has not proper permission to do changes to CodeCommit

2. Create Repository At CodeCommit

Simply create new repository by clicking Create repository, add repository name and description(optional) and click Create.

3. Check Existing SSH Key

  1. Open Terminal
  2. Enter following to see is there existing SSH keys:
   ls -al ~/.ssh
  1. Check the listing for existing SSH key. By default, public keys are one of the following:
    • id_dsa.pub
    • id_ecdsa.pub
    • id_ed25519.pub
    • id_rsa.pub

4. Generate New SSH Key

Create new SSH key if there is not existing key:

  1. Open Terminal
  2. Enter following to generate SSH key:
   ssh-keygen -t rsa -b 4096 -C "your_email@domain.com"

I prefer to set SSH key location to save as default and passphrase is optional as you can set additional security layer.
You can find newly generated SSH private and public keys under ~/.ssh folder.

5. Add SSH Public Key to AWS IAM User

  1. Copy SSH Public Key to Clipboard: Let's say id_rsa.pub public SSH key is already existing. Copy this to clipboard by following terminal command:
   pbcopy < ~/.ssh/id_rsa.pub
  1. Upload SSH Public Key to IAM User Add copied public SSH key to SSH keys for AWS CodeCommit under Security credential tab.
  2. Copy SSH Key ID of added SSH key This SSH Key ID will be added to ~/.ssh/config.

6. Add/Edit SSH Config file

Create config file under ~/.ssh if it's not created yet and add following lines:

Host git-codecommit.*.amazonaws.com
  User APKA5R243QHS7VQYN7O2
  IdentityFile ~/.ssh/codecommit_rsa

7. Init Existing Project as Git

  1. Open Terminal
  2. Initialize existing project directory as a git repository, add files in the directory and commit:
   git init
   git add .
   git commit -m "First commit"
  1. Add remote repository URL and push:
   git remote add origin <remote_repository_url>
   git push -u origin master

Check created CodeCommit repository and existing local project files should be found.

Top comments (1)

Collapse
 
santosh profile image
Santosh Kumar

I just realized I can use the same clone URL to add it as remote. 🤦‍♂️