Table of contents
- What is CodeBuild?
- Why we use AWS CodeBuild:
- Today I am sharing a Blog on AWS CodeCommit &AWS CodeBuild. I hope you will like it.
- AWS CodeCommit
- Let's setup an IAM User for AWS CodeCommit.
- Now we will see how to add HTTP GitCredentials in your AWS IAM.
- Now we will see how to create a repository in AWS CodeCommit.
- Let's create an EC2 Instance that will clone our CodeCommit Repository.
- Now Before moving forward Go to CodeCommit and click on Clone URL and copy the HTTPS URL.
- Let's setup an IAM User for AWS CodeCommit.
- Now we will see how to add HTTP GitCredentials in your AWS IAM.
- Now we will see how to create a repository in AWS CodeCommit.
- Let's create an EC2 Instance that will clone our CodeCommit Repository.
- Now Before moving forward Go to CodeCommit and click on Clone URL and copy the HTTPS URL.
- Task-01 :
- Task-02 :
In the Upcoming next 4 days, I will be making an CI/CD pipeline
on AWS with these tools.
CodeCommit
CodeBuild
CodeDeploy
CodePipeline
S3 Bucket
What is 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 toprovision
,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 ownbuild servers
.On-demand โ CodeBuild scales on demand to meet your
build needs
. You pay only for thenumber of build minutes you consume
.Out of the box โ CodeBuild provides
preconfigured build environments
for the most popularprogramming languages
. All you need to do is point to your build script to start your first build.
Why we use AWS CodeBuild:
Automated build process
Scalable for any workload size
Cost-effective pay-as-you-go pricing
Seamless integration with AWS services and third-party tools
Customizable build environments
Secure build and testing environment
Supports multiple programming languages and platforms
Detailed logs and monitoring capabilities
Today I am sharing a Blog on AWS CodeCommit &AWS CodeBuild. I hope you will like it.
- First, we will make AWS Commit and then move to AWS CodeBuild but if have already watched my previous blog then you can skip this part.
AWS CodeCommit
Let's setup an IAM User for AWS CodeCommit.
- Step-01: Go to the IAM service in
AWS Console
and click on Users and then click on Add User.
- Step-02: Click on
Next:Permissions
and then click onAttach existing policies directly
and then selectAWSCodeCommitFullAccess
then click onNext:Tags
.
- Step-03: Click on
Next:Review
and then click onCreate User
and thus we have created an IAM User forAWS CodeCommit
.
Now we will see how to add HTTP GitCredentials in your AWS IAM.
- Step-01: Go to IAM > Users > Security Credentials.
Step-02: Scroll down to
HTTPS Git credentials for AWS CodeCommit
and then click onGenerate credentials
HTTPS Git credentials for AWS CodeCommit > Generate > Download Credentials.
- Thus we have
Generated Credentials
for ourIAM User
saved it in a safe place it will be used in the future.
Now we will see how to create a repository in AWS CodeCommit.
- Step-01: Go to CodeCommit service in
AWS Console
and click on Create repository.
- Step-02: Enter the
Repository name
and then click onCreate repository
.
- Thus we have created a Repository in AWS CodeCommit.
Let's create an EC2 Instance that will clone our CodeCommit Repository.
- Step-01: Go to EC2 service
AWS Console
and click on Launch Instance and then select Ubuntu Server 22.04 and then click on Select.
- Step-02: Select t2.micro and then use existing
key-pair
or create newkey-pair
.
- Step-03: Click on
Network Settings
.
- Now log in to the EC2 instance via SSH and open Terminal.
Now Before moving forward Go to CodeCommit and click on Clone URL and copy the HTTPS URL.
- **Step-01:**Now we will
clone the CodeCommit Repository
in ourEC2 Instance.
git clone <HTTPS URL>
# The URL which is copied from CodeCommit
# Enter the UserName and Password which we downloaded for HTTP and git credentials.
- After this, we can see that the
repository
iscloned
in ourlocal machine
.
ls
cd <repository which we have cloned>
- Let's create a file in our repository and then push it to CodeCommit.
vim index.html
- Thus we have created a
index.html
file in our repository or you can use your own.
- Now we will push our code to
AWS CodeCommit.
git add .
git commit -m "Added index.html file"
git push origin master
- Thus we have pushed our code to
AWS CodeCommit
.
- (So this is what we have learned on Day 50 of #90DaysofDevOps. Now we will see how to use AWS CodeBuild.)
Task-01 :
Read about the Buildspec file for Codebuild it can be written in YAML or JSON.
version:
Specifies the version
of theBuildSpec file
. The current version is 0.2.phases: This section defines the
different phases
of thebuild process
, such asinstall
,pre_build
,build
,post_build
, andfinalize
. Each phase can have aseries of commands
will beexecuted in order
.artifacts: In this section, you
specify the files
anddirectories
that should bepackaged
and made available asbuild artifacts
after thebuild process is complete
. These artifactscan be used in the subsequent deployment stages.
cache: If you want to
speed up
thebuild process
by caching certain dependencies or build artifacts, you canspecify caching settings
in this section.environment: Here, you can
define environment variables
that will be availableduring the build process
. You can set variables specific toeach build phase
orshared across all phases
.source: Defines the
source code
location for thebuild
. You specify the repository type (e.g.,GitHub, Bitbucket
), thesource code location
, and anyauthentication credentials
if needed.logs: Specifies the configuration for
storing build logs
, such as theAWS S3 bucket
optionalencryption settings.
Task-02 :
Let's create a buildspec.yml
file in our repository for our index.html file.
version: 0.2
phases:
install:
commands:
- echo Installing NGINX
- sudo apt-get update
- sudo apt-get install nginx -y
build:
commands:
- echo Build started on 'date'
- cp index.html /var/www/html/
post_build:
commands:
- echo Configuring NGINX
artifacts:
files:
- /var/www/html/index.html
- Create
vim buildspec.yml
a file in your repository.
- Now we will push this file to our repository.
git add .
git commit -m "Added buildspec.yml file"
git push origin master
- Now let's create a
CodeBuild
project inAWS Console
.
- Step-01:
Create a CodeBuild Project
.
- Step-02:
Give a name
to yourCodeBuild Project
.
- Step-03:
Select your source provider
andrepository
.
- Step-04:
Select your environment
andoperating system
.
Thus we have created our
CodeBuild Project
.Now we will
start the build
so click onStart Build
.
- Wait for Untill the
Build is finished
.
Now we will create an AWS S3 bucket to add our build artifacts.
- Step-01: Go to
AWS S3
andcreate a bucket
.
- Step-02:
Give a name
to yourbucket
andcreate it
.
- Thus we have created our
S3 bucket
.
Now go to CodeBuild
and edit
your CodeBuild Project
and edit artifacts
.
- Step-01: Go to
CodeBuild
andedit
yourCodeBuild Project
andedit artifacts
.
- Step-02:
Select
yourS3 bucket
andgive a name
to yourbuild artifacts
.
- Step-03:
Save
yourchanges
andstart the build
again so that theartifacts
areuploaded
to yourS3 bucket
.
- Step-04:
Wait
until thebuild is finished
and after this checkbuild is finished
go to yourS3 bucket
andcheck
if theartifacts
areuploaded
or not.
- Step-05: Now go inside your
artifacts
and then /var/www/html/ and check if theindex.html
the file is present or not.
- Step-06: Click on the open button and check if the
index.html
the file is present or not.