Book Image

AWS Automation Cookbook

By : Nikit Swaraj
Book Image

AWS Automation Cookbook

By: Nikit Swaraj

Overview of this book

AWS CodeDeploy, AWS CodeBuild, and CodePipeline are scalable services offered by AWS that automate an application's build and deployment pipeline. In order to deliver tremendous speed and agility, every organization is moving toward automating their entire application pipeline. This book will cover all the AWS services required to automate your deployment to your instances. You'll begin by setting up and using one of the AWS services for automation –CodeCommit. Next, you'll learn how to build a sample Maven and NodeJS application using CodeBuild. After you've built the application, you'll see how to use CodeDeploy to deploy the application in EC2/Auto Scaling. You'll also build a highly scalable and fault tolerant Continuous Integration (CI)/Continuous Deployment (CD) pipeline using some easy-to-follow recipes. Following this, you'll achieve CI/CD for a microservice application and reduce the risk within your software development life cycle globally. You'll also learn to set up an infrastructure using CloudFormation templates and Ansible, and see how to automate AWS resources using AWS Lambda. Finally, you'll learn to automate instances in AWS and automate the deployment lifecycle of applications. By the end of this book, you'll be able to minimize application downtime and implement CI/CD, gaining total control over your software development lifecycle.
Table of Contents (11 chapters)

Introducing AWS CodeCommit - Amazon managed SaaS Git

AWS CodeCommit is a version control system, which is managed by Amazon Web Services, where we can privately store and manage assets in the Cloud and integrate with AWS. It is a highly scalable and secure VCS that hosts private Git repositories and supports the standard functionality of Git, so it works very well with your existing Git-based tools.

The following are the benefits of CodeCommit:

  • Managed service: CodeCommit is fully managed, distributed, fault tolerant, and carries no administrative overhead. It is elastic (able to adapt to a high workload) and, as mentioned, integrated with other AWS services.
  • No limit to storage and file type: We can store as many files as we want, because CodeCommit does not have space limitations. We can store not only source code but also documents and binary files.
  • Data and access security: CodeCommit repositories are encrypted while they are in AWS CodeCommit or when getting cloned somewhere. It is also integrated with IAM for user-level or specific API-level security.
  • HA (high availability): Whatever data we push into the repository, it will replicate across AZs (Availability Zones).
  • Easy migration of Git-based repository: We can easily migrate a remote Git-based repository to AWS CodeCommit.

These are some limitations or drawbacks of self-hosted VCS (BitBucket/GitHub/GitLab), which you won't find in AWS CodeCommit:

  • We may have to pay a license fee on a per-developer basis
  • We may end up with high hardware maintenance costs and high support staffing costs
  • Limitation on the amount and types of files that can be stored and managed
  • Limitation on the number of branches, the amount of version history, and other related metadata that can be stored

How to do it...

AWS CodeCommit is configured just like other Git-based repositories, such as GitHub. The following diagram shows how we use a development machine, AWS CLI/AWS Console, and CodeCommit to create and manage a repository:

(Reference: AWS CodeCommit Docs)

The basic workflow is described as follows:

  1. Using AWS CLI or CodeCommit Console, we can create a CodeCommit repository.
  2. Post that, use git clone in the CodeCommit repository URL on your local development machine.
  3. Once the repository gets cloned into the development machine, make the changes in the repository by adding to or editing the files. After that, enter the git add command and put it into the staging area, commit by giving a change message, and then push it back to the repository.
  4. After that, we can carry out git pull to synchronize the code in the AWS CodeCommit repository with our local repository. At this point in time, you will be working with the latest changes and the versions of the files.