Day 50: CI/CD pipeline on AWS - Part-1 ๐Ÿš€

Day 50: CI/CD pipeline on AWS - Part-1 ๐Ÿš€

ยท

6 min read

In the Upcoming next 4 days, I will be making a CI/CD pipeline on AWS with these tools.

  • CodeCommit

  • CodeBuild

  • CodeDeploy

  • CodePipeline

  • S3 Bucket

What is CodeCommit?

  • AWS CodeCommit is a fully-managed source control service that hosts secure Git-based repositories. It makes it easy for teams to collaborate on code in a secure and highly scalable ecosystem. CodeCommit eliminates the need to operate your own source control system or worry about scaling its infrastructure. We can use CodeCommit to securely store anything from source code to binaries, and it works seamlessly with your existing Git tools.

Why do we use CodeCommit?

  • CodeCommit is a managed source control service by AWS allows users to store, manage, and version their source code and artifacts securely and at scale. It supports Git, integrates with other AWS services, and 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.

Features of AWS CodeCommit:

  • Collaborative Software Development: AWS CodeCommit facilitates collaboration among software development teams by providing version control capabilities such as code commit, branching, and merging, ensuring smooth teamwork and project management.

  • Secure Data Transfer and Storage: CodeCommit allows users to transfer code to and from repositories securely using HTTPS or SSH. Additionally, repositories are automatically encrypted at rest through AWS Key Management Service (KMS) using customer-specific keys, ensuring data security.

  • Access Control and Monitoring: AWS Identity and Access Management (IAM) is used to control and monitor access to CodeCommit repositories, allowing administrators to set permissions for individuals or groups and track repository access through AWS CloudTrail and AWS CloudWatch.

  • High Availability and Durability: CodeCommit stores repositories in Amazon S3 and Amazon DynamoDB, leveraging the redundancy of these services to provide high availability and durability for your codebase across multiple facilities.

  • Easy Integration and Notifications: CodeCommit supports all Git commands, enabling seamless integration with existing Git tools and workflows. Users can receive notifications for repository events through Amazon SNS, and custom scripts or AWS Lambda functions can be triggered in response to these events for additional automation and notifications.

Task-01 :

Let's Setup an IAM User for AWS CodeCommit.

  • Step-01: Go to the IAM service in AWS Console.

Screenshot from 2023-08-02 23-11-45

  • Step-02: Click on Users and then click on Add User.

Screenshot from 2023-08-02 23-13-31

  • Step-03: Enter the User name and then provide console access to person "IAM USER" and create a custom password for the user so that whenever login to the console, the user will be asked to change the password for secutiry reasons.

Screenshot from 2023-08-02 23-16-46

  • Step-04: Click on Next:Permissions and then click on Attach existing policies directly and then select AWSCodeCommitFullAccess then click on Next:Tags.

Screenshot from 2023-08-02 23-18-16

  • Step-05: Click on Next:Review and then click on Create User.

Screenshot from 2023-08-02 23-18-30

  • Step-06: Now, click on Download .csv it and save it on your local machine for future use.

Screenshot from 2023-08-02 23-18-48

  • Thus we have Successfully created an IAM User with AWSCodeCommitFullAccess a policy.

Screenshot from 2023-08-02 23-22-13


How to add HTTP GitCredentials in your AWS IAM.

  • Step-01: Go to IAM > Users > Security Credentials.

Screenshot from 2023-08-02 23-28-57

  • Step-02: Scroll down to HTTPS Git credentials for AWS CodeCommit and then click on Generate credentials

  • HTTPS Git credentials for AWS CodeCommit > Generate > Download Credentials.

Screenshot from 2023-08-02 23-29-20

  • Thus we have Generated Credentials for our IAM User.

Screenshot from 2023-08-02 23-29-40


Set up a code repository on CodeCommit and clone it on your local.

  • Step-01: Go to the CodeCommit service in AWS Console.

Screenshot from 2023-08-02 23-38-12

  • Step-02: Click on Create repository.

Screenshot from 2023-08-02 23-39-04

  • Step-03: Enter the Repository name and then click on Create repository.

Screenshot from 2023-08-02 23-39-35

  • Step-04: Now, click on Clone URL and then copy the HTTPS URL.

imageedit_2_6433028831

Before Moving to TASK-02, Let's create a New EC2 Instance and Install Git in it so that we can clone the repository in our local machine.

  • Step-01: Go to the EC2 service in AWS Console.

Screenshot from 2023-08-03 16-24-53

  • Step-02: Click on Launch Instance.

Screenshot from 2023-08-03 16-25-18

  • Step-03: Select Ubuntu, SSD Volume Type and then click on Select.

Screenshot from 2023-08-03 16-26-17

  • Step-04: Select t2.micro and then select keypair.

Screenshot from 2023-08-03 16-26-35

  • Step-05: Click on Network Settings.

Screenshot from 2023-08-03 16-26-49

  • Thus we have created EC2 instance on which we can use our CodeCommit HTTPS URL to clone the repository.

Screenshot from 2023-08-03 16-27-43

  • Now log in the EC2 instance via SSH and open Terminal.

Task-02 :

Before Doing anything check if Git is installed in the EC2 instance for use

sudo apt update
sudo apt install git

Clone the repository in your local machine.

git clone <HTTPS URL>
# The URL which is copied from CodeCommit
# Enter the UserName and Password which we downloaded for HTTP and git credentials.

Screenshot from 2023-08-03 00-03-42

  • After this, we can see that the repository is cloned in our local machine.
ls
cd <repository which we have cloned>

Screenshot from 2023-08-03 00-04-05

Add a new file from local and commit to your local branch.

  • Step-01: Create an new file in the repository which we have cloned.
touch file{01..05}.txt

Screenshot from 2023-08-03 00-04-54

  • From now here we will use Git Commands.
# For Example
git add
git status
git commit -m
git push
  • Step-02: We will use git status to check the status of the repository unstaged or staged.
git status

Screenshot from 2023-08-03 00-05-23

  • Step-03: We will use git add to add the files to the staging area.
# git add . will add all the files to staging area.
git add .

Screenshot from 2023-08-03 00-05-51

  • Step-04: Now we will use git commit -m to commit the files to the local branch.
# git commit -m <Your Message>
git commit -m "Added 5 files"

Screenshot from 2023-08-03 00-09-43

  • Step-05: Now we will use git push to push the files to the remote repository.
git push origin master

Screenshot from 2023-08-03 00-10-45

So we can check Pushed the local changes to the CodeCommit repository.

  • Step-01: Go to CodeCommit service in AWS Console.

Screenshot from 2023-08-03 00-11-26

  • Step-02: Click on Repositories and then click on Repository Name.

Screenshot from 2023-08-03 00-11-37

  • Thus we have pushed the local changes to CodeCommit repository.


Did you find this article valuable?

Support DevOps by becoming a sponsor. Any amount is appreciated!

ย