Getting Started with CodeCommit

Setting up CodeCommit

This tutorial is written for the linux environment and uses SSH as the communication protocol.

  1. First, we need an IAM user that has full access to the AWS CodeCommit service. You can either create a new user and attach the appropriate policy to it or use an existing user.
  2. Next, we install Git on the instance.
  3. In order to associate the IAM user with full CodeCommit access with the EC2 instance, we will create an ssh-key pair on the instance and link it with the IAM user through the AWS console. While logged in to the instance, perform the following steps <ul style="list-style-type: disc;">
  4. ssh-keygen
    1. Enter a file name. Example code_commit
    2. Enter the passphrase if required and press enter
  5. This will generate two files:  The private key file code_commit and the public key file code_commit.pub. Copy the contents of the public key and save it (we’ll require it in the following steps)
  6. </ul>
    
  7. Go to the IAM console, choose Policies and then select IAMUserSSHKeys. Click on Attach and then select the IAM user we created/chose in the first step. Click on Attach Policy
  8. Go back to the IAM console and click on Users. Select our IAM user, scroll down and click on Upload SSH public key. Paste the text you copied previously and click Upload SSH public key
  9. Copy the SSH Key ID that will be generated and save it
  10. Inside the instance, create a file “config” inside ~/.ssh with the following contents

  11. Save the file and modify permissions: <ul style="list-style-type: disc;">
  12. chmod 600 config
  13. </ul>
    
  14. Test the SSH connection to CodeCommit <ul style="list-style-type: disc;">
  15. <span class="hljs-tag">ssh</span> <span class="hljs-tag">git-codecommit</span><span class="hljs-class">.us-east-1</span><span class="hljs-class">.amazonaws</span><span class="hljs-class">.com</span>
  16. </ul>
    
  17. If you get a public key denied error, try moving your config and key files to the .ssh directory of the root user.

Creating a Repository

  1. Go to the CodeCommit Console. Create a new repository and give it a name and description (optional).
  2. Create a new directory on your instance. <ul style="list-style-type: disc;">
  3. mkdir skywide
  4. </ul>
    
  5. Add the directory to git by running <ul style="list-style-type: disc;">
  6. git init skywide (This will create a .git directory inside skywide)
  7. </ul>
    
  8. Make a simple file inside the directory in order to test if the implementation is working, say index.html <ul style="list-style-type: disc;">
  9. sudo nano index.html
  10. </ul>
    
  11. Add the index.html file to git <ul style="list-style-type: disc;">
  12. git add index.html
  13. </ul>
    
  14. Run git status <ul style="list-style-type: disc;">
  15. git status
  16. </ul>
    
  17. To connect the instance to the repo you created on CodeCommit <ul style="list-style-type: disc;">
  18. git remote add origin ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/SkyWide
  19. </ul>
    
  20. In order to commit the file to the repo, run <ul style="list-style-type: disc;">
  21. git commit -m "First Commit"Where -m is a message flag that adds a comment to the commit.
  22. </ul>
    
  23. In order to push the commit to CodeCommit, run <ul style="list-style-type: disc;">
  24. git push origin master
    This pushes the master (your local repo) to origin (the CodeCommit repo set in step 7).
  25. </ul>
    

Comments