Continuous Cloning of CodeCommit Repo in Multiple Regions Using CodeBuild and CodePipeline
Tags: codecommit, codebuild, codepipeline, aws
Published: 2023-02-07 17:44:09

“ I have to make a continuous clone of the code commit repository in multiple regions. I have checked various ways to do it but it's easy to do using codebuild and codepipeline. Pricing of codebuild and codecommit depends on commit users and build project time taken.”

AWS CodeBuild is a fully managed build service. It compiles your source code, tests and produces artifacts that are ready to deploy. It eliminates the need to provision, scale and manage build servers. It provides prepackaged build environments for programming languages and build tools. Also build environments in codebuild to use your own build tools. Codebuild scales automatically to meet the peak build requests. 

In this post, you will get to know how to do continuous cloning of codecommit repo in multiple regions using codebuild and codepipeline. Here I have created codecommit repo, codebuild, codepipeline and iam role with required permission policies.

#Architecture Overview
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h3oh48f2trf3d9dlq35g.png)
The architecture diagram shows the overall deployment architecture with data flow, aws codecommit repo, aws codebuild, iam role and aws codepipeline.

#Solution overview
The blog post consist of the following phases:
1. Create of CodeCommit Repo, CodeBuild, CodePipeline and IAM Role
2. Output as Source CodeCommit Repo Branches with Files to Destination CodeCommit Repo

##Phase 1: Create of CodeCommit Repo, CodeBuild, CodePipeline and IAM Role
1. Open the CodeCommit console and create a repository in two regions(N.Virginia and Oregon). Also create CodeBuild with clone script of clone and CodePipeline with commit and build stage. For permission on build, assign permission of commit repo of both region with git pull and push on build role. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w9u6s0rirsydse2syiwm.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qdgmg5442rhnxb2auybd.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pdyxldtf1r0heorv5ggr.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zzopbrpim7a64jgwq858.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y5b2oao4te8l0sr5fhx3.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6483x6m7qrb8eyx74dc5.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3qbsrgbttizx1nakkhaz.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cxu92q248fpw10cdf43r.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t9v3izff2g9ztt3mybqj.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2lnf8vlpw1l03wx4zte4.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/94hztwzcs16umvh10n4i.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yzyczes4zvo5mcdecxd6.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/81wpy4xa2p92y4v0o3vq.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qfo8joxl9exv1we0glat.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h1nd73jpgstwo96ydq4q.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/blhv3emhryzf8sd294ip.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/311sg49m67rcgbsldwwd.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yczmhsm327coxssu778m.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6jpq3stx107tiex38mt4.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/avy7m7flo6dr82nj7p4b.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r1uibytnl64u5dbj1t4x.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cwxwfjr4ne66ozur0bwt.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6erj36diu5wdxfq8gpoe.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wfosujjm1h731sa5a2ye.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jvm9hgnwq7kgay7embx2.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/16li8kaw56ccmz0cqodb.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3iyh1d6e3ybpxkj6mjjf.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tsl3hafjuguuj2925csc.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mtvy41s1107s9dl5ueq1.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ncrwunvc6etdd9g10gtw.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wsaw61lfdvf164bg70j6.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p9ra3z0brx1yuy6j2f6a.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9sgrstlkfr725ugkzdf1.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wg1kgacpp9s3nechidle.png)

##Phase 2: Output as Source CodeCommit Repo Branches with Files to Destination CodeCommit Repo 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h3q70tltayj2e4qr6k2o.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3qm4dttramlsksur9jej.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v4usngh7v2o2710z2ma4.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rgex56t8npwf9948f4dq.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1af6pmujpc1fmyp7qr2w.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/naux2qhcpqbm3thv9hdl.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/im2hobrg2c23qce3duw6.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u7su06roci3pehzqvvsz.png)

#Clean-up
Delete CodeCommit Repo, CodeBuild Project, CodePipeline, IAM Role and CloudWatch Log Group.

#Pricing
I review the pricing and estimated cost of this example. 

Cost of CodeBuild = Free Tier - 100 build minutes on build.general1.small = $0.0

Cost of CodeCommit = $0.00 for first 5 CodeCommit users = $0.0

Cost of CloudWatch = First 5GB per month of log data ingested is free = $0.0

Total Cost = $0.0

#Summary
In this post, I showed “continuous cloning of codecommit repo in multiple regions using codebuild and codepipeline”.

For more details on AWS CodePipeline, Checkout Get started AWS CodePipeline, open the [AWS CodePipeline console](https://ap-south-1.console.aws.amazon.com/codesuite/codepipeline/pipelines?region=ap-south-1&pipelines-meta=eyJmIjp7InRleHQiOiIifSwicyI6eyJwcm9wZXJ0eSI6InVwZGF0ZWQiLCJkaXJlY3Rpb24iOi0xfSwibiI6MTAsImkiOjB9). To learn more, read the [AWS CodePipeline documentation](https://docs.aws.amazon.com/codepipeline/?id=docs_gateway). 

For more details on AWS CodeBuild, Checkout Get started AWS CodeBuild, open the [AWS CodeBuild console](https://us-east-1.console.aws.amazon.com/codesuite/codebuild/start?region=us-east-1). To learn more, read the [AWS CodeBuild documentation](https://docs.aws.amazon.com/codebuild/?id=docs_gateway).

Thanks for reading!

Connect with me: [Linkedin](https://www.linkedin.com/in/gargee-bhatnagar-6b7223114)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38sdi4nsp89fnui8h7dk.png)