AWS CodeCommit Tutorial for DevOps Implementation in Cloud

By Vijay

By Vijay

I'm Vijay, and I've been working on this blog for the past 20+ years! I’ve been in the IT industry for more than 20 years now. I completed my graduation in B.E. Computer Science from a reputed Pune university and then started my career in…

Learn about our editorial policies.
Updated March 7, 2024

DevOps Using AWS (Amazon Web Services) CodeCommit Repository:

In our previous tutorial on DevOps with Microsoft VSTS, we came to know more about VSTS.

In this new 3 part series, I will focus on a hands-on approach for DevOps (CI and CD) using Amazon Web Services (AWS) cloud DevOps service tools.

                   Also Read => Whole Range of DevOps Tutorials

AWS CodeCommit Repository

Introduction

Let’s just recap on what the various tools are with the help of the below diagram:

AWS Codepipeline

  • AWS CodeCommit: It is a secure online version control service which hosts the private Git repositories. A team need not maintain their own version control repository instead, they can use AWS CodeCommit to store their source code or even binaries like the WAR/JAR/EAR files that are generated out of the build.
  • AWS CodeBuild: It is a build service on the cloud with the help of which the teams can compile their source code and produce the target artifacts which can be made available for deployment. Since the compilation is done on the cloud you don’t need to provide any particular build server.
  • AWS CodeDeploy: It is the deployment service which automates the deployment of the application to the Amazon EC2 Linux or Windows instances.
  • AWS CodePipeline: It helps to provide a visual view of the end to end delivery process and is configured with the above AWS DevOps tools.

Also as Jenkins is one of the most popular CI tools that is used today by most of the organizations and we will also take a look at how these AWS DevOps tools integrate with it.

In this first tutorial, I will focus on AWS CodeCommit and how your source code and other artifacts can be securely stored in this repository. The entire series will be using a simple J2EE web project.

Pre-Requisite:

  • Account with AWS preferably a free tier.
  • Git installed on your local machine.
  • Eclipse IDE.
  • AWS Region used – Asia Pacific (Singapore).
  • Most importantly a very good and fast internet connection.

Creating AWS CodeCommit repository

Login to the AWS Management Console. An AWS account is required to log in. I have used the free tier one. Once you have successfully logged in, launch the AWS CodeCommit web service and create a repository.

Enter a name and description and click on Create repository.

Create Repository

The empty repository is created as shown below.

Empty Repository

Creating an IAM User

IAM users have to be created for the team members as a part of the working with the source code in a repository using IDE’s like Eclipse and appropriate full CodeCommit access has to be given. This defines the access to the team as part of security.

As CodeCommit repositories are privately hosted Git repositories in the cloud, you will need Git credentials for every IAM user to communicate with the CodeCommit repository over HTTPS.

So typically the J2EE project will be created and with help of the Git credentials and Git commands (E.g. git push, git pull etc.) the project will be pushed to the CodeCommit repository. The communication will be done over HTTPS.

We will see the procedure for one IAM user and you can repeat the same steps for multiple users.

#1) Create an IAM user and provide access.

Go to the IAM service in AWS. Click on the Users category -> Add User.

Add User Screen

Enter the Username and Programmatic Access check box for the Access type. Click Next->Permissions.

User Details

Set full access permission of AWS CodeCommit for the user.

Set Permissions Screen

Click Next->Review

Review Screen

Click on Create user.

Remember to download or copy the Access Key ID and Secret key access. This will be used for multiple services. So it is very important to keep them available handy at any point. As an AWS admin, you will need to email them to the users.

Click Close once done.

Add User Screen

#2) Generate the Git credentials for the user.

Click on the newly created user and go to the Security Credentials TAB.

Security Credentials Tab

Security Credentials Screen

Click on Generate button under HTTPS Git credentials for AWS CodeCommit.

This credentials will also have to be emailed to the users. So you can copy or download them. Click Close once copied.

AWS CodeCommit

The above 2 steps have to be performed for every user who needs to work on the CodeCommit repository.

Creating a J2EE Web project in Eclipse

As a developer, you would be using any of IDE’s available for Java/J2EE code development.

Let’s assume that Eclipse is the IDE which is used in this case. Using this IDE we will create a Maven based J2EE web project and push the contents to the CodeCommit repository for the team to work with.

Before we create the project, install the CodeCommit into Eclipse using the AWS Toolkit plugin. Click here to update the site. This will help to communicate directly to the CodeCommit repository from the IDE using Git commands.

Install Software Screen

Open the AWS Explorer view and the AWS CodeCommit should be visible.

AWS Code Commit Screen

Now create an AWS Java Web Project and add the code to the index.html file as shown below.

AWS Java Web Project

New AWS Java Web Project

Click to Configure AWS accounts and enter the IAM user Access Key and Secret Key created earlier and click Finish.

AWS Toolkit

AWS-Index.html

Ensure that the EGit plugin is also installed. Share the project created to the local GIT repository and push the code to the CodeCommit repository. Right-Click on the project and select Team -> Share Project.

Team-Share Project screen

Share Project

Click Next and Create a new repository in an appropriate folder on the local machine.

Configure GIT Repository

Create New GIF File

Click Finish.

Configure Git Repository

Click Finish.

Commit the changes to the local Git repository. Right-Click on the project and select Team->Commit.

Team-Commit Screen

Drag and Drop the files from Unstaged Changes to Staged changes and click on the Commit button.

AWS Commit Screen

Now as we have the repository locally committed we can now push the local repository to our CodeCommit repository that was created earlier.

Firstly copy the Clone URL HTTPS from the AWS CodeCommit console.

AWS Code Screen

Back in Eclipse right-click and select Team -> Push Branch ‘master’.

Push Branch Master Screen

Select HTTPS protocol and paste the Clone URL HTTPS and enter the Git credentials created as part of the IAM user.

Destination Git Repository

Click Next.

Push Button in Remote

Click Next.

Push Branch Master screen

Click Finish to push the changes to the CodeCommit repository. Once completed the successful message screen should appear.

Push Results

The above commit and push commands can also be done using command line using Git commands (git commit and git push) if one is comfortable with the same.

The repository should now be updated with the eclipse project code. Once the code is available the other developers can clone the repository and make it available on their local machines for further development and push the code back to the CodeCommit repository using standard git commands or from the Eclipse IDE.

The instructions to clone the repository is available as you click on the CONNECT button of the CodeCommit repository.

AWS Screen

Jenkins Integration with AWS CodeCommit

Jenkins is one of the popular tools for Continuous Integration. Teams today would like to leverage Jenkins for their CI activities. So as a part of the CI pipeline instead of connecting to GitHub repository you can connect to the CodeCommit repository and provide the IAM user credentials for build activities.

Here is a screenshot for the same where Jenkins references the CodeCommit Clone URL HTTPS for the repository using the IAM user credentials.

Once the repository is referenced as a part of the Source Code Management then the other actions of the Build and Post-Build are as usual that you would normally do with Git repositories.

Git repositories

Summary

The main idea in this series of tutorials is to showcase how DevOps can be implemented on the AWS cloud platform.

As everyone is aware that one of the strong pre-requisites for DevOps is to have a good version control repository, in this tutorial we have seen how to create and configure CodeCommit repository to store your project artifacts and also integration with Jenkins which is a very popular CI tool used for Build and Deploy.

The upcoming tutorial in this series will explain how the code in the CodeCommit repository will be used to BUILD.

PREV Tutorial | NEXT Tutorial

Was this helpful?

Thanks for your feedback!

Leave a Comment