CI/CD pipeline on AWS : Part-1

CI/CD pipeline on AWS : Part-1

What is CodeCommit ?

  • CodeCommit is a managed source control service by AWS that allows users to store, manage, and version their source code and artifacts securely and at scale. It supports Git, integrates with other AWS services, enables collaboration through branch and merge workflows, and provides audit logs and compliance reports to meet regulatory requirements and track changes. Overall, CodeCommit provides developers with a reliable and efficient way to manage their codebase and set up a CI/CD pipeline for their software development projects.

Setup for HTTPS users using Git credentials

The simplest way to set up connections to AWS CodeCommit repositories is to configure Git credentials for CodeCommit in the IAM console, and then use those credentials for HTTPS connections. You can also use these same credentials with any third-party tool or integrated development environment (IDE) that supports HTTPS authentication using a static user name and password.

Step 1: Initial configuration for CodeCommit

Follow these steps to set up an Amazon Web Services account, create an IAM user, and configure access to CodeCommit.

To create and configure an IAM user for accessing CodeCommit
  1. Create an IAM user, or use an existing one, in your Amazon Web Services account. Make sure you have an access key ID and a secret access key associated with that IAM user.

  2. In the IAM console, in the navigation pane, choose Users, and then choose the IAM user you want to configure for CodeCommit access.

  3. On the Permissions tab, choose Add Permissions.

  4. In Grant permissions, choose Attach existing policies directly.

  5. From the list of policies, select AWSCodeCommitPowerUser or another managed policy for CodeCommit access.

  6. After you have selected the policy you want to attach, choose Next: Review to review the list of policies to attach to the IAM user. If the list is correct, choose Add Permissions.

    Your User has created with Acess to AWSCodeCommit

Step 2: Create Git credentials for HTTPS connections to CodeCommit

  1. In the IAM console, in the navigation pane, choose Users, and from the list of users, choose your IAM user.

  2. On the user details page, choose the Security Credentials tab, and in HTTPS Git credentials for AWS CodeCommit, choose Generate.

  3. Copy the user name and password that IAM generated for you, either by showing, copying, and then pasting this information into a secure file on your local computer, or by choosing Download credentials to download this information as a .CSV file. You need this information to connect to CodeCommit.

    After you have saved your credentials, choose Close.

Note: This is your only chance to save the user name and password. If you do not save them, you can copy the user name from the IAM console, but you cannot look up the password. You must reset the password and then save it.

Setting Up a Code Repository on AWS CodeCommit:

  1. Sign in to the AWS Management Console with newly created user and Open the CodeCommit Dashboard:

    • Navigate to the AWS Management Console and Sign in with your AWS account.

    • In the "Find Services" box, type “CodeCommit” and select the service.

  1. Create a CodeCommit Repository:

    • Click on the "Create repository" button.

    • Provide a name for your repository.

    • Provide a description.

    • Click "Create"

  2. Get Connection Details:

    • Once the repository is created, you will need to select how you want to connect to this repository. You will generally have two main options: HTTPS or SSH. For this example, let's go with HTTPS.

    • Click on the "Clone URL" drop-down and select "HTTPS".

    • Copy the HTTPS URL (You'll need this URL later to clone the repository).

Set Up Credentials and Clone Repository Locally

  1. Install Git (if it isn’t already installed):

  2. Install the AWS CLI (if it isn’t already installed):

  3. Configure the AWS CLI:

    • Run aws configure and provide the necessary AWS credentials (Access Key, Secret Key, Region). Ensure that these credentials have the necessary permissions for CodeCommit.
  4. Configure Git with AWS Credentials Helper:

    • Run the following command to tell Git to use the AWS CLI as a credential helper:

        git config --global credential.helper '!aws codecommit credential-helper $@'
        git config --global credential.UseHttpPath true
      
  5. Clone the Repository:

    • Navigate to the directory on your local machine where you want to clone the repository.

    • Use the HTTPS URL you copied earlier and run:

        git clone [HTTPS_URL]
      

      Replace [HTTPS_URL] with the URL you copied from the CodeCommit dashboard.

  6. You should now have the repository cloned on your local machine, and you can start adding, committing, and pushing changes as with any other Git repository.

    When clone, it does ask for Git Credentials, once provide it clone to local.

Remember, AWS IAM roles and permissions can be tricky, so ensure that the AWS credentials you use have the correct permissions to perform actions with CodeCommit. If you encounter permission errors, you might need to adjust your IAM policies accordingly.

Add a new file from local and commit to your local branch; Created manually

Adding the 1.txt file manually

  • Pushed the local changes to CodeCommit repository.

  • Go to AWS Management Console and validate

    Here I see the same file and this is how you can establish the connection between CodeCommit and local!

    This is how you create a repo in AWS using CodeCommit, Clone it to Local and Push your changes!

    Stay Tuned! We have just started! 😃