DevOps on AWS: Part 1 — Exploring CodeCommit and CodeBuild

@Harsh
5 min readApr 1, 2024

--

OverView:

Welcome to the first part of our DevOps journey on AWS! In this series, we’ll dive deep into various AWS services to build a robust Continuous Integration and Continuous Deployment (CI/CD) pipeline. In this first blog, we’ll explore CodeCommit and CodeBuild, two essential components for automating the software development process.

CodeCommit

AWS CodeCommit is a fully managed source control solution offered by Amazon Web solution. It is a version code service. By using the CodeCommit service, you can effortlessly work with your existing Git tools. You may easily save your source code and other files, as well as push, pull, and commit data. It makes it easy for teams to host secure and highly scalable Git repositories.

Here’s How To Get Started.

1. Create a new repository:

  • Log in to the AWS Management Console.
  • Navigate to the CodeCommit service.
  • Click on “Create repository” and follow the prompts to set up your repository.
  • Create a IAM user for this repo because it can’t be login with root user.

Add following permissions to this user.

Generate credentials for this user. Navigate to section “security credentials > HTTPS Git credentials for AWS CodeCommit”

Download the credentials after creating it from here.

2. Clone the repository:

  • Once the repository is created, clone it to your local machine using Git.
git clone <repo-url>

Note: Git should be installed on your local machine.

  • It will ask for credential, copy the credentials we have downloaded for user code-commit-repo.

3. Add files and commit changes:

  • Add you first project files and commit the changes. We have index.html file here.

CodeBuild:

CodeBuild compiles your source code, runs unit tests, and produces artifacts that are ready to deploy. CodeBuild eliminates the need to provision, manage, and scale your own build servers.

Here’s how to set up a build project:

1. Create a build project:

  • Navigate to the CodeBuild service in the AWS Management Console.
  • Click on “Create build project”.
  • Configure the build settings including source provider (CodeCommit), environment, and buildspec file.
  • Now for the next section that is artifacts, you have to create a S3 bucket.
  • Go to Amazon S3 dashboard and click on create bucket.

Click on ACL enabled and unclick Block all public access for avoiding any kind of errors.

After creating this bucket, create one folder inside it where codebuild will store the build files.

  • Now add this bucket information into artifacts section in code build configuration.

2. Define Build Specifications:

A buildspec is a collection of build commands and related settings, in YAML format, that CodeBuild uses to run a build. Without a build spec, CodeBuild cannot successfully convert your build input into build output or locate the build output artifact in the build environment to upload to your output bucket.

  • Create a buildspec.yml file in the root of your CodeCommit repository.
  • Define the build phases such as install, pre-build, build, and post-build commands in the buildspec.yml
  • After creating this, add the file and commit the changes and push it into your code commit repo.

3. Start A Build:

  • After uploading your buildspec.yml file, start your build.
  • You can trace your build in Phase details section of your project.
  • Verify by going to your artifacts manually, that is S3 bucket whether your build is uploading there or not.

And your build is finally successfull completed.

Conclusion:

In this first part of our series, we explored the fundamentals of CodeCommit and CodeBuild. We learned how to set up a Git repository using CodeCommit and automate the build process using CodeBuild. Stay tuned for the next part where we’ll delve into CodeBuild and CodeDeploy to complete our CI/CD pipeline on AWS.

[ LINK TO PART 2 : https://harsh05.medium.com/devops-on-aws-part-2-exploring-codebuild-and-codedeploy-92c1f20c3ba4 ]

[ LINK TO PART 3: https://harsh05.medium.com/devops-on-aws-part-3-creating-a-complete-ci-cd-pipeline-with-codepipeline-1c594d0f3add ]

--

--

@Harsh
@Harsh

Written by @Harsh

A devOps engineer from India

No responses yet