AWS Automation Cookbook
上QQ阅读APP看书,第一时间看更新

Introduction

Deployment is the activity that will make your software available, that is, ready for end customer or market. So basically when we have tested the code, the post building process, we will have the build artifacts, which we need to deploy to the production machine so that the latest feature should be available for the end users to use.

Deployment can be done manually as well as automatically. Sometimes, some enterprises keep this process manual, but most of the companies are automating it. Let's list out the benefits of automated deployment:

  • Less error prone and more repeatable: Manual deployments are error-prone because it involves human interference. It's obvious that sometime deployment engineers forget to perform important steps in a release accidentally, which leads to incorrect versions of software, or broken software will get deployed, which of course is not wanted. When it comes to automated deployment, it doesn't suffer from variability; once the configuration and process is set, it will be the same in every deployment.
  • Anyone can deploy: In a manual or partial-automated deployment, specific expertise of build and release are required. The deployment will be the responsibility of specific people in an organization. But when it comes to the automated deployment process, the knowledge of releasing software is captured in the system, not in an inpidual’s brain.
  • Deploying to another environment is not a problem anymore: Automated deployments are configurable and give lots of flexibility (depending on the tool). Although the base release process is permanent, the target environments and machines can be changed easily, so the overhead of deploying to that additional target is negligible.

There are a couple of very famous tools around the world, which help the enterprise to automate their deployments process. For example, Jenkins, AWS CodeDeploy, CircleCi, and so on. In this chapter, we will be looking at AWS CodeDeploy.

AWS CodeDeploy is the deployment service provided by AWS that automates the deployment of the application to Amazon EC2 instance, Elastic Beanstalk, and on-premise instances. It provides the facility to deploy unlimited variants of application content such as code, configuration, scripts, executables, multimedia, and much more. CodeDeploy can deploy application files stored in Amazon S3 buckets, GitHub repositories, or BitBucket repositories.

AWS CodeDeploy makes it easier to rapidly release new features and helps in avoiding downtime during application deployment. It also handles the complexity of updating applications, without many of the risks associated, which can occur due to manual deployment.

Benefits of AWS CodeDeploy

AWS CodeDeploy provides lots of benefits. Some of them are listed as follows:

  • Automated deployments: AWS CodeDeploy automates the deployment of your application across all environments, such as development, test, and production. It scales your infrastructure in such a way that you can deploy to one instance or hundreds of instances. 
  • Decrease downtime: AWS CodeDeploy increases application availability. It has all the inbuilt configuration that  needs to be carried out during the deployment phase. For example, during the blue-green deployment, once the deployment is done, traffic rerouting to the instances will be taken by AWS CodeDeploy only.
  • Stop and roll back: You can stop and rollback deployments if there are any errors.

Components of AWS CodeDeploy

Before deep ping with CodeDeploy, first let's see the terminologies that are used in the reference of CodeDeploy.

  • Application: It represent the application name that needs to get deployed. This name also ensures the correct combination of the deployment group, configuration, and revision.
  • Deployment configuration: It consists of a set of deployment rules and some condition of deployment success and failure used by CodeDeploy at the time of deployment.
  • Deployment group: It represents the inpidual tagged instances or an instance in auto scaling groups where the deployment needs to be done.
  • Deployment type: The deployment strategy used to make the latest application available on instances or auto scaling after the deployment. AWS CodeDeploy provides two different deployment types:
    • In-place deployment
    • Blue-green deployment

               The deployment type is discussed in details in the next section of this chapter.

  • IAM instance profile: IAM instance profile is basically an IAM role that needs to get attached with Amazon EC2 instances. This role should have the permission to access the S3 bucket or GitHub, where the latest revision of the application is stored. 
  • Revision: It is basically an archive file, which contains source code, deployment scripts, and the AppSpec.yml file. It is stored in the S3 bucket or GitHub repository.
  • Service role: It's an IAM role, which provides permission to an AWS service to access AWS resources. The details of which AWS resources needs to get accessed by the AWS service should be mentioned in policy that is attached. In case of AWS CodeDeploy, a service role generally has the following permissions:
    • Reading the tags of instances and auto scaling groups  to identify the instances in which an application can get deployed.
    • Performing operations on instances, auto scaling groups, and ELB.
    • Accessing SNS for publishing information and CloudWatch for alarm monitoring.
  • Target revision:  This is basically the latest application code, which is tagged for the next deployment. It is stored in either the S3 or GitHub repository. 

Make sure to install the AWS CodeDeploy agent on every instance of the deployment group that will be used by AWS CodeDeploy for the deployment purpose.

In this chapter, we will be seeing the deployment of build artifact in to the production server using AWS CodeDeploy. We will discuss some deployment strategies that will help in deploying the build artifacts without hurdles and with less or no downtime. The application specification file is also discussed. Post that, we will see how AWS CodePipeline will help in automating the pipeline with AWS resources such as AWS S3 and AWS CodeDeploy. Specifically, we will see the following points:

  • Working with the AWS CodeDeploy deployment types
  • Using CodeDeploy deployment types and writing AppSpec.yml
  • Deploying one static application in an EC2 instance from the S3 bucket
  • Configuring CodePipeline with CodeDeploy
  • Creating a CI/CD pipeline with AWS CodeDeploy