1 00:00:01,080 --> 00:00:03,160 - [Alana] Hello, and welcome back. 2 00:00:03,160 --> 00:00:06,040 Our development team is getting to the end of a sprint. 3 00:00:06,040 --> 00:00:09,620 Some exciting new features are coming to the application. 4 00:00:09,620 --> 00:00:11,740 Now, we have to start thinking about how we are going 5 00:00:11,740 --> 00:00:13,080 to deploy the application 6 00:00:13,080 --> 00:00:16,250 to get those features in front of our customers. 7 00:00:16,250 --> 00:00:18,120 We've spoken about different deployment strategies 8 00:00:18,120 --> 00:00:21,110 for the application, and the team has decided they want 9 00:00:21,110 --> 00:00:22,940 to use the service, AWS CodeDeploy, 10 00:00:22,940 --> 00:00:25,750 to take our build artifact, getting built by CodeBuild, 11 00:00:25,750 --> 00:00:28,563 and deploy this to our application instances. 12 00:00:29,810 --> 00:00:32,750 CodeDeploy supports deploys to EC2 instances, 13 00:00:32,750 --> 00:00:34,420 on-premises physical servers, 14 00:00:34,420 --> 00:00:37,890 AWS Lambda, and Amazon ECS. 15 00:00:37,890 --> 00:00:41,380 Our application is hosted on EC2 instances. 16 00:00:41,380 --> 00:00:42,940 To get started with CodeDeploy, 17 00:00:42,940 --> 00:00:45,090 we will need to create an application, 18 00:00:45,090 --> 00:00:47,570 and one or more deployment groups. 19 00:00:47,570 --> 00:00:50,120 Let's go through what each of these means. 20 00:00:50,120 --> 00:00:52,180 An application defines the compute platform 21 00:00:52,180 --> 00:00:53,550 we are deploying to. 22 00:00:53,550 --> 00:00:55,810 This is a choice of the supported platforms: 23 00:00:55,810 --> 00:01:00,720 EC2/on-premises, Lambda, and ECS. 24 00:01:00,720 --> 00:01:02,570 I'm deploying to EC2 instances, 25 00:01:02,570 --> 00:01:06,223 so I would use the EC2/On-premises compute platform. 26 00:01:07,780 --> 00:01:10,430 An application can have multiple deployment groups. 27 00:01:10,430 --> 00:01:12,020 For an EC2 server deployments, 28 00:01:12,020 --> 00:01:13,780 the deployment group needs to know information 29 00:01:13,780 --> 00:01:16,187 about several things, like: 30 00:01:16,187 --> 00:01:18,290 The IAM role that CodeDeploy will use 31 00:01:18,290 --> 00:01:20,890 to authenticate to other services. 32 00:01:20,890 --> 00:01:24,810 The deployment style, whether it's in-place or blue/green. 33 00:01:24,810 --> 00:01:27,830 In-place will replace the application on our instances, 34 00:01:27,830 --> 00:01:30,830 and blue/green will create new green instances 35 00:01:30,830 --> 00:01:32,203 to deploy the application. 36 00:01:33,420 --> 00:01:35,990 Then, we have to specify the deployment configuration. 37 00:01:35,990 --> 00:01:37,270 For an EC2 deploy, 38 00:01:37,270 --> 00:01:39,390 this controls the number or percentage 39 00:01:39,390 --> 00:01:42,453 of healthy hosts we want available during a deployment. 40 00:01:43,460 --> 00:01:46,310 We also have to specify how to find our instances 41 00:01:46,310 --> 00:01:48,780 by tags, Auto Scaling group, 42 00:01:48,780 --> 00:01:52,010 or even on-premises tagged instances. 43 00:01:52,010 --> 00:01:53,410 For a blue/green deploy, 44 00:01:53,410 --> 00:01:55,190 we can configure an Auto Scaling group 45 00:01:55,190 --> 00:01:58,403 that CodeDeploy will copy to provision the green instances. 46 00:01:59,260 --> 00:02:01,440 Specifically for a blue/green deploy, 47 00:02:01,440 --> 00:02:03,770 you have control over when to route the traffic 48 00:02:03,770 --> 00:02:05,550 to the green instances. 49 00:02:05,550 --> 00:02:08,200 It can be automatic or the deploy can wait for you 50 00:02:08,200 --> 00:02:11,410 to continue the deployments when you're happy to go ahead. 51 00:02:11,410 --> 00:02:13,440 You also control how long the original, 52 00:02:13,440 --> 00:02:17,233 or blue, instances are kept after successful deploy. 53 00:02:18,370 --> 00:02:20,970 Optionally, you can also select a load balancer, 54 00:02:20,970 --> 00:02:23,190 so CodeDeploy knows where to register 55 00:02:23,190 --> 00:02:26,720 and deregister instances during the deployment. 56 00:02:26,720 --> 00:02:29,030 We can also associate CloudWatch alarms. 57 00:02:29,030 --> 00:02:30,220 A deployment can be halted 58 00:02:30,220 --> 00:02:32,280 if any of the configured CloudWatch alarms go 59 00:02:32,280 --> 00:02:34,590 into an alarm state. 60 00:02:34,590 --> 00:02:36,880 And finally, auto rollback. 61 00:02:36,880 --> 00:02:38,430 If we want to automatically rollback 62 00:02:38,430 --> 00:02:40,170 on a deployment failure, 63 00:02:40,170 --> 00:02:41,200 a rollback is just going 64 00:02:41,200 --> 00:02:44,333 to redeploy the last successful deployment for you. 65 00:02:46,340 --> 00:02:48,960 With an application and deployment group in place, 66 00:02:48,960 --> 00:02:51,220 I'm ready to create a deployment. 67 00:02:51,220 --> 00:02:54,500 A deployment for EC2 just needs to know my application, 68 00:02:54,500 --> 00:02:57,860 the deployment group, and the revision of my application. 69 00:02:57,860 --> 00:03:00,680 The revision is the artifact we want to deploy. 70 00:03:00,680 --> 00:03:03,170 This will contain all the files and instructions run 71 00:03:03,170 --> 00:03:05,540 on each host during the deployments. 72 00:03:05,540 --> 00:03:09,200 These instructions are configured in an AppSpec file. 73 00:03:09,200 --> 00:03:12,780 We will go into a lot more detail on the AppSpec file, 74 00:03:12,780 --> 00:03:15,220 and the hooks you have to run your commands 75 00:03:15,220 --> 00:03:16,523 during a deployment, later. 76 00:03:17,400 --> 00:03:20,810 How exactly are these commands run on my instances, though? 77 00:03:20,810 --> 00:03:23,740 Well, this is the job of the CodeDeploy agent. 78 00:03:23,740 --> 00:03:25,640 We need to have the agent installed 79 00:03:25,640 --> 00:03:27,470 and running on all of the instances 80 00:03:27,470 --> 00:03:30,130 where we plan to deploy the application. 81 00:03:30,130 --> 00:03:32,420 The link on your screen goes to more details 82 00:03:32,420 --> 00:03:34,650 on how to install the CodeDeploy agent. 83 00:03:34,650 --> 00:03:37,200 I'll also include this link in the course readings. 84 00:03:38,400 --> 00:03:41,840 An EC2 deployments from CodeDeploy can pick up this artifact 85 00:03:41,840 --> 00:03:44,660 from S3 or from a GitHub commit. 86 00:03:44,660 --> 00:03:46,520 When CodeDeploy is added as part 87 00:03:46,520 --> 00:03:48,981 of an AWS CodePipeline action, 88 00:03:48,981 --> 00:03:50,946 the revision can be picked up from the output 89 00:03:50,946 --> 00:03:53,061 of another CodePipeline action, 90 00:03:53,061 --> 00:03:54,797 for example, the artifacts created 91 00:03:54,797 --> 00:03:57,214 from a pipeline build phase. 92 00:03:57,214 --> 00:04:00,810 Here's Russ to show you more about this in the console. 93 00:04:00,810 --> 00:04:02,120 - [Russ] Let's jump into the console, 94 00:04:02,120 --> 00:04:05,400 and see how all of this works with a simple deployment. 95 00:04:05,400 --> 00:04:06,670 From inside the console, 96 00:04:06,670 --> 00:04:10,540 I can create a CodeDeploy application. 97 00:04:10,540 --> 00:04:12,550 This is just the application name, 98 00:04:12,550 --> 00:04:17,053 and the compute platform we are deploying to, EC2 instances. 99 00:04:22,930 --> 00:04:25,883 Now, I create the deployment group. 100 00:04:26,940 --> 00:04:28,203 We give it a name. 101 00:04:33,070 --> 00:04:35,763 I choose the service role. 102 00:04:37,260 --> 00:04:39,570 This is the role it will use to authenticate 103 00:04:39,570 --> 00:04:42,090 to other AWS services. 104 00:04:42,090 --> 00:04:43,580 Our deployment type, 105 00:04:43,580 --> 00:04:47,200 let's start simple with an in-place deployment. 106 00:04:47,200 --> 00:04:49,560 CodeDeploy needs to know which instances 107 00:04:49,560 --> 00:04:51,260 that we want to deploy to, 108 00:04:51,260 --> 00:04:54,383 so I'm going to give it an EC2 instance name tag. 109 00:05:06,800 --> 00:05:11,800 We are given an option to install the CodeDeploy agent 110 00:05:12,120 --> 00:05:13,420 on our instances. 111 00:05:13,420 --> 00:05:16,370 I don't need to do this because I already have this set up. 112 00:05:17,870 --> 00:05:21,070 For deployment settings, let's do all at once. 113 00:05:21,070 --> 00:05:23,380 This will mean an outage for our application, 114 00:05:23,380 --> 00:05:25,500 but I'm deploying to a dev environment 115 00:05:25,500 --> 00:05:28,450 and I want to deploy as fast as I can. 116 00:05:28,450 --> 00:05:31,090 I have a load balancer set up, 117 00:05:31,090 --> 00:05:32,690 so I can tell CodeDeploy 118 00:05:32,690 --> 00:05:35,133 about my load balancer target group, here. 119 00:05:38,870 --> 00:05:42,430 I now have an application and a deployment group set up. 120 00:05:42,430 --> 00:05:45,970 I have everything I need to create a deployment. 121 00:05:45,970 --> 00:05:47,940 This will send an application revision 122 00:05:47,940 --> 00:05:50,440 to the deployment group we just created. 123 00:05:50,440 --> 00:05:52,940 Let me show you what a simple revision looks like. 124 00:05:53,990 --> 00:05:57,020 I have a revision open in an editor here. 125 00:05:57,020 --> 00:06:00,260 The revision contains a simple AppSpec file, 126 00:06:00,260 --> 00:06:04,160 the scripts I have specified to run with each of the hooks, 127 00:06:04,160 --> 00:06:07,993 and a single source file I want to deploy on my instances. 128 00:06:10,640 --> 00:06:12,160 Back in the CodeBuild console, 129 00:06:12,160 --> 00:06:16,173 from my deployment group, I can choose Create deployment. 130 00:06:19,270 --> 00:06:23,200 All I need to supply here is the location of my revision. 131 00:06:23,200 --> 00:06:25,100 I have zipped up the contents of my revision 132 00:06:25,100 --> 00:06:27,310 and copied this to an S3 bucket. 133 00:06:27,310 --> 00:06:30,283 I can enter the S3 location of my revision. 134 00:06:35,600 --> 00:06:39,830 I can override some deployment group settings, here. 135 00:06:39,830 --> 00:06:42,200 I'll just keep this set to all at once, 136 00:06:42,200 --> 00:06:44,153 and then choose Create deployment. 137 00:06:49,790 --> 00:06:53,240 My deploy completed in about a minute and a half. 138 00:06:53,240 --> 00:06:57,830 If I choose View events here for one of my instances, 139 00:06:57,830 --> 00:07:01,720 I see the sequence of events that happen during the deploy. 140 00:07:01,720 --> 00:07:04,930 BlockTraffic is the event that deregistered the instance 141 00:07:04,930 --> 00:07:06,387 from the load balancer. 142 00:07:06,387 --> 00:07:09,050 AllowTraffic is the event that registered it back. 143 00:07:09,050 --> 00:07:14,050 ApplicationStop and BeforeInstall are the two steps 144 00:07:14,390 --> 00:07:17,000 where my revision scripts ran. 145 00:07:17,000 --> 00:07:20,720 These events all ran simultaneously on my instances, 146 00:07:20,720 --> 00:07:21,553 where you're using 147 00:07:21,553 --> 00:07:24,070 the all-at-a-time deployment configuration, 148 00:07:24,070 --> 00:07:25,250 for this deployment. 149 00:07:25,250 --> 00:07:27,160 If we were to use one at a time 150 00:07:27,160 --> 00:07:29,150 for the deployment configuration, 151 00:07:29,150 --> 00:07:31,100 one instance would be selected, 152 00:07:31,100 --> 00:07:33,660 all of the events we see here would complete. 153 00:07:33,660 --> 00:07:37,680 Only then would CodeDeploy move to the next instance. 154 00:07:37,680 --> 00:07:40,620 That was a pretty quick introduction to CodeDeploy. 155 00:07:40,620 --> 00:07:43,710 We have spoken about CodeDeploy's application, 156 00:07:43,710 --> 00:07:47,320 deployment group, deployments, and revisions. 157 00:07:47,320 --> 00:07:50,440 We saw the deployment run against my five instances, 158 00:07:50,440 --> 00:07:53,360 where the CodeDeploy agent followed the instructions 159 00:07:53,360 --> 00:07:57,193 in my AppSpec file to get my applications installed.