Working With Code in an AWS CodeCommit Repository Demo
Start course

This course provides you with an introduction to AWS CodeCommit and how it can be used to manage your source code. 

Learning Objectives

  • Understand what the service is and the benefit it provides 
  • Learn the core functionality of the service
  • Learn the important features such as notifications, triggers, and approval rule templates
  • Understand how to use the service

Intended Audience

  • Those who are implementing or managing CI/CD pipelines on AWS
  • Those who want to better understand CodeCommit and how it fits into a software development process
  • Anyone taking an AWS certification, such as the AWS Developer - Associate certification 




At this point, the CodeCommit repository is created and I’ve already connected to it using my terminal via HTTPS. In this lecture, I’ll be committing code to the repository, working with multiple branches, and creating a pull request. Let’s get started. 

Here we are in the terminal, and I’ve already cloned my repository called WebAppRepo. Let’s go ahead and take a look at this repo using the command cd WebAppRepo.

Currently, this repository is empty. However, I can change this by copying files into this directory, or for simplicity, I can just create an index.html file using the command vim index.html. Then I’ll edit this file to add an h1 header that says “hello from cloud academy!”. 

From here, I can save the file. Then I’ll do git status, and we can see our new file in red here, which means we need to add it to our next commit. I’ll run the command git add index.html. We can do another git status and see that the index.html file is now in green and needs to be committed.

To do this, I’ll type git commit and then I’ll add -m and provide a message of “initial commit of files”. For the final step, all we have to do is push these files. I’ll type in git push to push the files to the CodeCommit repository. You can see the progress of the push as it’s happening, and eventually, it’s successful. 

Let’s go back to the CodeCommit console and see if our newly created file is present in the repo. To do this, I’ll click on the repository name and if I click on my file, I can see my very simple html. 

Suppose I want to make a change to the file. I can either edit directly in the console or go back to the terminal and open my file once more using vim. I’ll go ahead and go back to the terminal. This time, I’m going to make a branch called newFeature using the command git checkout -b newFeature.

Now, I’m going to make my changes. Let’s view my file by using the command vim index.html. And this time, I’m going to add some extremely simple css to this file. In this case, I’ll change the color of the h1 to blue, using <h1 style=”color:blue;”>. I’ll then save the file, and run git add index.html, git commit -m with a message of “changed h1 color to blue” and then I’ll run git push. Here I get a message saying I need to set an upstream for the current branch I’m on, so I’ll just copy this command and paste it.

Now if I head back to the CodeCommit console, I’ll click on commits on the left-hand side. You can see I don’t see my new commit here and that’s because it’s only showing commits to the main branch. Let’s select my newFeature branch, and by doing that, I can now see the latest commit. 

In the commits panel, I can visualize my commits, as well as compare commits to one another. If I click on the commit ID, CodeCommit will show us the lines changed within the file. Now that we have a newFeature, let’s go ahead and submit a pull request to merge the changes from this branch into the main branch. 

To do this, I’ll click on pull requests and then create pull request. The destination will be the main branch, and the source will be the newFeature branch. Then I’ll click compare. 

It verifies that it is mergeable. I’ll give it a title, such as newFeatureMerge, and scroll down to review my changes. Looks like it shows the addition of my simple css, so I can go ahead and click create pull request. From there I’ll click on Merge. Then I can choose my preferred merging strategy, which is the default strategy in this case, and then click merge once again. 

Now I can see a green success label of “merged”. If I go back to my code and click on index.html, I can see the changed color of blue now. There are of course ways to manage this all from the CLI, however, it’s pretty simplistic in the console as well. That’s it for this one - see you next time! 

About the Author
Learning Paths

Alana Layton is an experienced technical trainer, technical content developer, and cloud engineer living out of Seattle, Washington. Her career has included teaching about AWS all over the world, creating AWS content that is fun, and working in consulting. She currently holds six AWS certifications. Outside of Cloud Academy, you can find her testing her knowledge in bar trivia, reading, or training for a marathon.