1 00:00:00,790 --> 00:00:02,600 - [Alana] We walked you through the core components 2 00:00:02,600 --> 00:00:05,420 of AWS CodeDeploy in a previous video, 3 00:00:05,420 --> 00:00:07,990 but it's time to get a bit deeper into one of them, 4 00:00:07,990 --> 00:00:09,970 the AppSpec file. 5 00:00:09,970 --> 00:00:12,570 It's important to have a good understanding of this file, 6 00:00:12,570 --> 00:00:15,380 as CodeDeploy relies on it heavily. 7 00:00:15,380 --> 00:00:18,200 This AppSpec is a YAML or JSON file 8 00:00:18,200 --> 00:00:21,160 that contains locations for all the installation files, 9 00:00:21,160 --> 00:00:24,940 scripts, and when to initiate specific actions. 10 00:00:24,940 --> 00:00:26,160 This is where you get to control 11 00:00:26,160 --> 00:00:28,680 how your revision deployments are actually managed, 12 00:00:28,680 --> 00:00:31,583 and how you determine a deployment was successful. 13 00:00:32,930 --> 00:00:34,370 Let's take a look at the AppSpec file 14 00:00:34,370 --> 00:00:36,350 that we'll be using later in the labs. 15 00:00:36,350 --> 00:00:38,010 Note that this is an AppSpec file 16 00:00:38,010 --> 00:00:41,180 that's used for Amazon EC2 based deployments. 17 00:00:41,180 --> 00:00:42,530 If you're looking for more information 18 00:00:42,530 --> 00:00:44,360 on serverless AppSpec files, 19 00:00:44,360 --> 00:00:47,020 check out the reading following this video. 20 00:00:47,020 --> 00:00:50,060 All right, so this AppSpec file is a YAML file, 21 00:00:50,060 --> 00:00:52,850 and it's pretty simplistic in nature. 22 00:00:52,850 --> 00:00:55,530 A lot of AppSpec files can get pretty complicated, 23 00:00:55,530 --> 00:00:57,770 but I'll talk you through all your options 24 00:00:57,770 --> 00:01:01,003 and why we chose the ones we did for this specific file. 25 00:01:02,210 --> 00:01:06,290 So, this file is broken out into four sections: 26 00:01:06,290 --> 00:01:11,010 version, os, files, and hooks. 27 00:01:11,010 --> 00:01:12,940 We could additionally have another section 28 00:01:12,940 --> 00:01:14,830 called the permissions section, 29 00:01:14,830 --> 00:01:17,340 which we'll talk about a bit later. 30 00:01:17,340 --> 00:01:18,780 Out of all the sections, 31 00:01:18,780 --> 00:01:22,690 the version and the os are the simplest parts. 32 00:01:22,690 --> 00:01:26,300 The version refers to the CodeDeploy AppSpec version, 33 00:01:26,300 --> 00:01:27,610 and not the version 34 00:01:27,610 --> 00:01:30,480 of your specific application or deployments. 35 00:01:30,480 --> 00:01:35,480 And currently, the only accepted value is 0.0. 36 00:01:35,700 --> 00:01:38,840 The os section, as you may have already guessed, 37 00:01:38,840 --> 00:01:41,090 stands for operating system, 38 00:01:41,090 --> 00:01:45,820 and it only accepts two possible values, Linux or Windows. 39 00:01:45,820 --> 00:01:48,370 The EC2 instance you'll be working with in the lab 40 00:01:48,370 --> 00:01:52,430 is a Linux box, so we chose Linux. 41 00:01:52,430 --> 00:01:55,100 Now, all the rest of the sections are optional. 42 00:01:55,100 --> 00:01:58,330 That means the hooks, files, and the permissions sections 43 00:01:58,330 --> 00:01:59,750 are not required. 44 00:01:59,750 --> 00:02:01,900 So let's talk about why. 45 00:02:01,900 --> 00:02:04,510 The files section is only necessary, 46 00:02:04,510 --> 00:02:06,950 if you're going to be copying files to your instance 47 00:02:06,950 --> 00:02:08,600 during the deployments. 48 00:02:08,600 --> 00:02:12,650 It has a source and destination subsection. 49 00:02:12,650 --> 00:02:16,370 The source subsection identifies a file or directory 50 00:02:16,370 --> 00:02:18,540 from your revision to copy. 51 00:02:18,540 --> 00:02:21,920 The destination identifies the location on this instance 52 00:02:21,920 --> 00:02:25,290 of where the file or directory should be copied. 53 00:02:25,290 --> 00:02:30,280 So for our AppSpec file, we want the index.html file 54 00:02:30,280 --> 00:02:31,763 to be copied to the 55 00:02:31,763 --> 00:02:36,296 var/www/html directory on our instance. 56 00:02:37,150 --> 00:02:38,770 The next section we are going to review 57 00:02:38,770 --> 00:02:41,020 is the hooks section. 58 00:02:41,020 --> 00:02:42,940 The hooks direct the CodeDeploy agent 59 00:02:42,940 --> 00:02:46,430 as to what it needs to do and in what sequence. 60 00:02:46,430 --> 00:02:49,557 Some of the main hooks that you can use are BeforeInstall, 61 00:02:49,557 --> 00:02:53,547 AfterInstall, ApplicationStart, ApplicationStop, 62 00:02:53,547 --> 00:02:56,030 and ValidateService. 63 00:02:56,030 --> 00:02:58,840 Each of these is used to run scripts that you specify 64 00:02:58,840 --> 00:03:00,780 when the hook is initiated. 65 00:03:00,780 --> 00:03:02,150 You'll notice that each of these hooks 66 00:03:02,150 --> 00:03:04,110 is structured the same way. 67 00:03:04,110 --> 00:03:06,860 You specify the location of the script, 68 00:03:06,860 --> 00:03:09,890 the timeout you want to allow for it to run, 69 00:03:09,890 --> 00:03:12,160 and if you're running a Linux deployment, 70 00:03:12,160 --> 00:03:13,850 runas refers to the level 71 00:03:13,850 --> 00:03:15,980 at which you want to run the script. 72 00:03:15,980 --> 00:03:19,130 Or, in other words, the user on your Linux instance 73 00:03:19,130 --> 00:03:22,243 you want to use to run the script, such as root. 74 00:03:23,530 --> 00:03:26,290 Note that we're not using every one of these hooks. 75 00:03:26,290 --> 00:03:29,259 In our file, we're only using three of these hooks, 76 00:03:29,259 --> 00:03:33,860 BeforeInstall, ApplicationStop, and ApplicationStart. 77 00:03:33,860 --> 00:03:35,710 That's because they're the only ones necessary 78 00:03:35,710 --> 00:03:37,970 for this deployment, so we've completely omitted 79 00:03:37,970 --> 00:03:40,100 the other options from the file. 80 00:03:40,100 --> 00:03:42,450 Let's talk about each of these hooks in detail. 81 00:03:43,470 --> 00:03:46,560 The Before and AfterInstall hooks are used for the script 82 00:03:46,560 --> 00:03:49,280 that you need to run before the installation happens, 83 00:03:49,280 --> 00:03:52,090 and after the installation is complete. 84 00:03:52,090 --> 00:03:54,300 For example, here, we're linking to a script 85 00:03:54,300 --> 00:03:56,700 that installs the dependencies 86 00:03:56,700 --> 00:03:59,040 needed to run our application. 87 00:03:59,040 --> 00:04:00,393 If I look at the script, 88 00:04:01,650 --> 00:04:04,680 you can see that I'm installing an Apache web server here, 89 00:04:04,680 --> 00:04:06,513 which is needed for the site. 90 00:04:08,180 --> 00:04:09,790 Going back to the AppSpec file, 91 00:04:09,790 --> 00:04:13,140 the ApplicationStop and ApplicationStart hooks 92 00:04:13,140 --> 00:04:15,310 are used to run any scripts needed to stop 93 00:04:15,310 --> 00:04:17,230 and start the application. 94 00:04:17,230 --> 00:04:20,890 We're using these hooks to start and stop our Apache server. 95 00:04:20,890 --> 00:04:24,240 So, looking at the start_server script in a text editor, 96 00:04:24,240 --> 00:04:27,840 you can see we're doing just that, starting the server. 97 00:04:27,840 --> 00:04:29,780 And in this stop_server script, 98 00:04:29,780 --> 00:04:30,770 you can see that I'm checking 99 00:04:30,770 --> 00:04:33,090 to see if the Apache web server is running, 100 00:04:33,090 --> 00:04:34,853 and if it is, I stop it. 101 00:04:35,720 --> 00:04:37,910 Now, there is another hook that you cannot use 102 00:04:37,910 --> 00:04:41,070 to initiate a script, and it's called Install. 103 00:04:41,070 --> 00:04:44,040 In CodeDeploy, the Install stage is just the stage 104 00:04:44,040 --> 00:04:46,280 where it copies over the files from the source 105 00:04:46,280 --> 00:04:49,060 to the destination on your behalf. 106 00:04:49,060 --> 00:04:51,190 Lastly, you can use the ValidateService hook 107 00:04:51,190 --> 00:04:53,630 to run any scripts that you will use to test 108 00:04:53,630 --> 00:04:55,820 and make sure that everything has been installed 109 00:04:55,820 --> 00:04:57,223 and started correctly. 110 00:04:58,250 --> 00:05:01,300 After the hooks, that leaves us with one last section, 111 00:05:01,300 --> 00:05:03,030 the permissions section. 112 00:05:03,030 --> 00:05:04,905 I'll go ahead and paste in 113 00:05:04,905 --> 00:05:07,430 a permissions section to this file, 114 00:05:10,690 --> 00:05:13,260 so that you can see some of the settings. 115 00:05:13,260 --> 00:05:15,210 The permissions section is only valid 116 00:05:15,210 --> 00:05:17,870 if the os setting is set to Linux. 117 00:05:17,870 --> 00:05:20,060 It refers to the permissions you want to apply 118 00:05:20,060 --> 00:05:23,250 to the files being copied in the file section. 119 00:05:23,250 --> 00:05:24,620 If you're specifying permissions, 120 00:05:24,620 --> 00:05:27,420 then the file section is required. 121 00:05:27,420 --> 00:05:29,900 I won't go through every part of the permissions, 122 00:05:29,900 --> 00:05:33,100 but I do want to state that if you use permissions, 123 00:05:33,100 --> 00:05:35,040 the one required part within permissions 124 00:05:35,040 --> 00:05:38,730 that you must include is the object section. 125 00:05:38,730 --> 00:05:41,610 Object refers to the set of system files, folders, 126 00:05:41,610 --> 00:05:43,610 or directories that the specified permissions 127 00:05:43,610 --> 00:05:46,470 are applied to after the file system objects 128 00:05:46,470 --> 00:05:48,620 are copied to the instance. 129 00:05:48,620 --> 00:05:50,180 There's a lot more to the AppSpec file 130 00:05:50,180 --> 00:05:51,820 that I can cover in this video, 131 00:05:51,820 --> 00:05:53,810 so make sure to check out the notes section 132 00:05:53,810 --> 00:05:56,340 for more information and resources. 133 00:05:56,340 --> 00:05:57,550 I'll also provide examples 134 00:05:57,550 --> 00:05:59,100 of how you can use the permissions section 135 00:05:59,100 --> 00:06:00,233 for your deployments.