DEV Community

Cover image for Getting Started with AWS CodeCommit: A Step-by-Step Guide
Arbythecoder
Arbythecoder

Posted on

Getting Started with AWS CodeCommit: A Step-by-Step Guide

Introduction:

This article is your personal guide to embracing the power of AWS CodeCommit. We will create AWS CodeCommit repository, connect to an Amazon EC2 instance, set up a local Git repository, make significant code changes, and relish the thrill of your first commit. This journey goes beyond step-by-step instructions; it's about equipping you with the skills and insights you need to master the intricacies of contemporary software development.

Task 1: Create an AWS CodeCommit repository

  1. Access the AWS Management Console
    • To begin, navigate to the AWS Management Console and search for "CodeCommit."
    • Select "CodeCommit" to access the service.

Image description

  1. Create a Repository
    • Click on "Create repository" within the CodeCommit service.
    • Provide a unique name for your repository, for example, "My-Repo."
    • Optionally, add a description like "My first repository."
    • Confirm the creation by clicking "Create."

Image description

Image description

Task 2: Connect to the Amazon EC2 Instance

  1. Access the EC2 Instance

    • As part of this lab, an EC2 instance has already been provisioned for you.
  2. Establish a Console Connection

    • Copy the "Ec2InstanceSessionUrl" value from the instructions.
    • Open a new web browser tab and paste the URL.
    • This will establish a console connection to your EC2 instance.

Image description

Image description

Task 3: Create a Local Repository Using Git

  1. Install Git on EC2 Instance

    • Within the EC2 instance terminal session, run the command: sudo yum install -y git.
  2. Configure Git Settings

    • Configure the Git credential helper to work with AWS CodeCommit and enable the use of HTTP paths.
  3. Clone AWS CodeCommit Repository

    • Retrieve the HTTPS URL of your AWS CodeCommit repository from the AWS CodeCommit console.
    • Use the git clone command to clone the repository to your EC2 instance.

Task 4: Making a Code Change and First Commit to the Repo

  1. Navigate to the Repository Directory

    • Change to the directory where you cloned the repository using cd ~/My-Repo.
  2. Create Example Files

    • Use the echo command to create two example files in your local repository.
  3. View List of Files

    • Check the files in the directory using the ls command.
  4. Stage Changes

    • Stage the created files for commit using git add.
  5. Check Repository Status

    • Use git status to view the status of your repository and the staged changes.
  6. Commit Changes

    • Commit the staged changes with a meaningful message using git commit -m "Added cat.txt and dog.txt".
  7. View Commit Details

    • To review the details of your commit, execute git log.

Image description

Image description

Image description

Image description

Image description

Image description

Task 5: Push Your First Commit

  1. Push Commit to AWS CodeCommit Repository

    • Push the commit from your local repository to your AWS CodeCommit repository using git push -u origin master.
  2. View the Repository in CodeCommit Console

    • Return to the AWS CodeCommit console in your web browser.
    • Refresh the page to see the files you added to your repository.

Image description

Conclusion:

Congratulations! By following these steps, you have successfully created a CodeCommit repository, connected to an EC2 instance, established a local Git repository, made code changes, and pushed your first commit. AWS CodeCommit offers a range of features for secure and efficient source code management, making it a valuable addition to your development workflow.

Are you eager to dive even deeper into AWS and continue your learning journey? AWS offers a fantastic opportunity to access free AWS Builder Labs to elevate your DevOps skills. You can explore these labs by visiting the following link: Free AWS Builder Labs.

Top comments (0)