AWS DevOps Project Part-1

AWS DevOps Project Part-1

AWS CodeCommit + AWS CodeBuild

Agenda: We need to deploy a HTML page by using AWS DevOps services through Nginx web server. Demonstration of:

  • how to Create a Git repository on AWS CodeCommit.

  • source code compilation of the repository using CodeBuild.

AWS CodeCommit:

AWS CodeCommit is a version control service hosted by Amazon Web Services that you can use to privately store and manage assets (such as documents, source code, and binary files) in the cloud.

AWS CodeBuild:

AWS CodeBuild is a fully managed build service in the cloud. 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. It provides prepackaged build environments for popular programming languages and builds tools such as Apache Maven, Gradle, and more. You can also customize build environments in CodeBuild to use your own build tools. CodeBuild scales automatically to meet peak build requests.

CodeBuild provides these benefits:

  • Fully managed – CodeBuild eliminates the need to set up, patch, update, and manage your own build servers.

  • On-demand – CodeBuild scales on demand to meet your build needs. You pay only for the number of build minutes you consume.

  • Out of the box – CodeBuild provides preconfigured build environments for the most popular programming languages. All you need to do is point to your build script to start your first build.

CodeCommit Process:

Creation of CodeCommit Repo:

Developer Tools-->CodeCommit-->Repositories-->Create repository

Enter Repository name: demo-app & create a repo.

CodeGuru: this is just like a sonarqube. Checks the code and inform if the code is wrong or has any mistakes.

CodeGuru Reviewer analyzes existing code bases in the repository, identifies hard-to-find bugs and critical issues with high accuracy, provides intelligent suggestions on how to remediate them, and creates a baseline for successive code reviews.

You can't configure SSH/ HTTP connection with your root A/C. You need to configure it trough IAM user.

Creation of IAM user:

Generate GIT credentials for AWS CodeCommit:

Click on "Generate Credentials"

Download it on the local system for further use.

GIT Clone this repo to local:

Click on "Clone HTTPS" for copying the remote URL of CodeCommit Repo.

Copying the CodeCommit Repo in your Local:

Open VS Code & clone

error: 403 due to non-binding of CodeCommit policy to IAM user.

IAM policy:

CodeCommit Repo "demo-app" is cloned to local.

Create an "index.html" in repo.

Git Operations:

  • git add

  • git commit

  • git push

Check the CodeCommit repo.

index.html page is added to CodeCommit repo "demo-app".

CodeCommit Operation:

  • Create some changes in index.html page.

  • Create new branch "dev".

  • perform git oprations.

  • push the update through new branch "dev".

Master branch:

Dev Branch:

Create a pull request for branch merging:

Merge the branches:

CodeBuild Process:

Developer Tools-->CodeBuild-->Build projects-->Create build project

Project name: demo-app-build

Source provider: AWS CodeCommit

Repository: demo-app

Reference type: Branch

Branch: Master (SOurce code of this branch will be compiled during CodeBuild process. )

Configure the Environment: Choose the operating system(Ubuntu) image that needs to be run on the server for building project.

Service role: New service role.

Role name (automatically defined for CodeBuild, can be edited.)

Buildspec file:

buildspec.yml: Configuration file for CodeBuild. A buildspec is a collection of build commands and related settings, in YAML format, that CodeBuild uses to run a build. You can include a buildspec as part of the source code or you can define a buildspec when you create a building project.

Perform the git operations in "dev" branch.

Create build project.

Start build:

This build process failed due to non-finding of "buildspec.yml" file(which is in dev branch).

Create a pull request for merging both branches.

Now both files are in the master branch.

Now this CodeBuild process succeeded.

Artifacts:

If you want your project to be built at a specific place, then we need to specify the artifact upload location.

Type: Amazon S3

Bucket name: select bucket of your AWS A/C, where we want to store the build code.

Name: "demo-app.zip" This is the zip file of the source code after CodeBuild process.

Path: "code-output-demo-app" folder under your S3 bucket where the zip file will be put. (No need to create this folder in S3, it'll be automatically created during the CodeBuild process.).

Update the artifacts.

Artifact packaging: zip

Again start the build process for verifying the compiled code(after CodeBuild process) stored at the artifact location(S3).

if we download this zip file. The contents of it will be verified.

That's all for part-1.

Hope this article will be helpful to you. Thanks for reading this article.

Thank you for reading!Happy Learning!!

Santosh Chauhan

Did you find this article valuable?

Support Santosh Chauhan's blog by becoming a sponsor. Any amount is appreciated!