1 00:00:00,140 --> 00:00:02,440 ‫Okay, so now let's get into CodeBuild 2 00:00:02,440 --> 00:00:05,770 ‫to see how we can use CodeBuild not to build this time 3 00:00:05,770 --> 00:00:09,490 ‫but to test our code in our CodePipeline. 4 00:00:09,490 --> 00:00:11,020 ‫So what do we want to test? 5 00:00:11,020 --> 00:00:13,000 ‫Well, if you look at our Beanstalk environment, 6 00:00:13,000 --> 00:00:15,630 ‫we really, really like that congratulations message. 7 00:00:15,630 --> 00:00:16,780 ‫I think we should have it, 8 00:00:16,780 --> 00:00:21,080 ‫and we want to test for this not ever leaving the screen, 9 00:00:21,080 --> 00:00:23,400 ‫so we never want congratulations to go away, 10 00:00:23,400 --> 00:00:24,870 ‫this is what we want to test for. 11 00:00:24,870 --> 00:00:27,960 ‫So for this, let's go to CodeBuild and get started. 12 00:00:27,960 --> 00:00:30,820 ‫We're going to create our first build project 13 00:00:30,820 --> 00:00:33,407 ‫and I will call it MyBuildProjects, 14 00:00:36,010 --> 00:00:37,830 ‫and the description is going to be 15 00:00:37,830 --> 00:00:41,293 ‫testing for congratulations. 16 00:00:42,170 --> 00:00:43,243 ‫So the idea is that we're going to have a script 17 00:00:43,243 --> 00:00:45,740 ‫that will test whether or not this congratulation word 18 00:00:45,740 --> 00:00:47,910 ‫are going to appear in our webpage. 19 00:00:47,910 --> 00:00:48,820 ‫So I'm going to scroll down 20 00:00:48,820 --> 00:00:50,240 ‫and for the source provider, 21 00:00:50,240 --> 00:00:52,670 ‫I'm going to choose CodeCommits 22 00:00:52,670 --> 00:00:56,780 ‫and the repository going to be my-nodejs-app. 23 00:00:56,780 --> 00:00:59,460 ‫So we can see here in the primary sources, 24 00:00:59,460 --> 00:01:02,087 ‫we can have S3, GitHub, Bitbucket, 25 00:01:02,087 --> 00:01:04,010 ‫and GitHub Enterprise for now, 26 00:01:04,010 --> 00:01:06,380 ‫and so as you can see, CodeBuild can be used 27 00:01:06,380 --> 00:01:08,200 ‫to test many different projects. 28 00:01:08,200 --> 00:01:09,400 ‫So we'll use my-nodejs-app, 29 00:01:09,400 --> 00:01:10,470 ‫we'll choose a branch, 30 00:01:10,470 --> 00:01:11,583 ‫and the branch is going to be the main branch, 31 00:01:13,680 --> 00:01:15,300 ‫and then we don't specify a commit ID, 32 00:01:15,300 --> 00:01:18,600 ‫that means we want to test the main branch at its latest. 33 00:01:18,600 --> 00:01:19,820 ‫Okay, that's great, 34 00:01:19,820 --> 00:01:23,520 ‫then I will scroll down and under environments, 35 00:01:23,520 --> 00:01:26,720 ‫I will choose a managed image or a custom image. 36 00:01:26,720 --> 00:01:29,580 ‫So the idea is that CodeBuild uses Docker in the backend 37 00:01:29,580 --> 00:01:31,210 ‫to create a testing environment, 38 00:01:31,210 --> 00:01:33,500 ‫and so we can use the managed images by AWS 39 00:01:33,500 --> 00:01:36,010 ‫to have the ready to use images 40 00:01:36,010 --> 00:01:38,460 ‫when we want to test for specific programming languages, 41 00:01:38,460 --> 00:01:41,230 ‫but if you want you to have your own programming environment 42 00:01:41,230 --> 00:01:42,150 ‫and your own testing environments, 43 00:01:42,150 --> 00:01:44,190 ‫you could provide your own custom image. 44 00:01:44,190 --> 00:01:45,900 ‫In terms of operating system, 45 00:01:45,900 --> 00:01:47,560 ‫it's recommended to use Ubuntu, 46 00:01:47,560 --> 00:01:49,270 ‫as you can see in this message, 47 00:01:49,270 --> 00:01:51,850 ‫so we use Ubuntu, and for the runtime, 48 00:01:51,850 --> 00:01:53,210 ‫we'll be using standard, 49 00:01:53,210 --> 00:01:56,490 ‫and the image, I'm going to use codebuild/standard:5.0, 50 00:01:56,490 --> 00:01:58,570 ‫but the rule of thumb is that if you see this video 51 00:01:58,570 --> 00:02:02,660 ‫and there's been new releases for this image, 6.0, 7.0, 52 00:02:02,660 --> 00:02:04,590 ‫please use the latest and it will make sure 53 00:02:04,590 --> 00:02:06,450 ‫that the code will work, okay? 54 00:02:06,450 --> 00:02:07,330 ‫Then the image version is 55 00:02:07,330 --> 00:02:10,660 ‫always used the latest image for this runtime version, 56 00:02:10,660 --> 00:02:11,880 ‫we'll use Linux, 57 00:02:11,880 --> 00:02:13,300 ‫and then we'll create a new service role 58 00:02:13,300 --> 00:02:17,300 ‫that will be used by this CodeBuild project. 59 00:02:17,300 --> 00:02:18,520 ‫The important thing you can see, 60 00:02:18,520 --> 00:02:20,380 ‫an interesting thing you can see is that 61 00:02:20,380 --> 00:02:22,640 ‫there are some additional configurations to this, 62 00:02:22,640 --> 00:02:25,070 ‫for example, we have timeouts where we can set 63 00:02:25,070 --> 00:02:27,010 ‫how long we want the default timeouts, 64 00:02:27,010 --> 00:02:29,300 ‫they must between five minutes and eight hours, 65 00:02:29,300 --> 00:02:30,790 ‫so this is good if you know 66 00:02:30,790 --> 00:02:32,500 ‫that the build can not last too long, 67 00:02:32,500 --> 00:02:35,630 ‫you should then set this to something very, very low. 68 00:02:35,630 --> 00:02:38,550 ‫The VPC is something very interesting, 69 00:02:38,550 --> 00:02:41,030 ‫you can select the VPC, and the CodeBuild project 70 00:02:41,030 --> 00:02:44,600 ‫will run the VPC for the the build from within the VPC, 71 00:02:44,600 --> 00:02:46,620 ‫and the idea is that you can access 72 00:02:46,620 --> 00:02:49,850 ‫your internal resources such as RDS databases and so on. 73 00:02:49,850 --> 00:02:52,320 ‫You can set how big you want your compute power to be 74 00:02:52,320 --> 00:02:54,930 ‫for this testing image, we will choose the lowest. 75 00:02:54,930 --> 00:02:56,183 ‫We can specify environment variables 76 00:02:56,183 --> 00:02:58,290 ‫that can come from different places, 77 00:02:58,290 --> 00:02:59,960 ‫the Parameter store, Secrets Manager, 78 00:02:59,960 --> 00:03:01,340 ‫or just be Plaintext, 79 00:03:01,340 --> 00:03:04,400 ‫and we can specify a file system. 80 00:03:04,400 --> 00:03:06,670 ‫Now, the most important thing from an exam perspective 81 00:03:06,670 --> 00:03:10,030 ‫is that now we have the buildspec configuration 82 00:03:10,030 --> 00:03:11,970 ‫and we need to use a buildspec file 83 00:03:11,970 --> 00:03:14,960 ‫to specify how we want to build our project in CodeBuild, 84 00:03:14,960 --> 00:03:19,400 ‫and as you can see, we have a buildspec name as optional, 85 00:03:19,400 --> 00:03:21,314 ‫and that means that by default, 86 00:03:21,314 --> 00:03:24,660 ‫CodeBuild will look for a file named buildspec.yml 87 00:03:24,660 --> 00:03:27,000 ‫in the source code root directory. 88 00:03:27,000 --> 00:03:29,060 ‫So the idea is really, you want to remember 89 00:03:29,060 --> 00:03:31,300 ‫that buildspec.yml is the name of the file 90 00:03:31,300 --> 00:03:33,930 ‫and it's placed at the source code root directory. 91 00:03:33,930 --> 00:03:35,760 ‫Okay, so we won't specify anything here, 92 00:03:35,760 --> 00:03:37,400 ‫we'll just use a buildspec file. 93 00:03:37,400 --> 00:03:38,630 ‫I will scroll down, 94 00:03:38,630 --> 00:03:41,250 ‫and then for Artifacts is do you want to create artifacts, 95 00:03:41,250 --> 00:03:44,980 ‫for example, pushing a Docker image to Amazon ECR, 96 00:03:44,980 --> 00:03:46,890 ‫no, and we could push it to Amazon S3 as well 97 00:03:46,890 --> 00:03:49,430 ‫if you wanted to, but I will choose no artifacts. 98 00:03:49,430 --> 00:03:51,570 ‫And then for logging, we can have CloudWatch 99 00:03:51,570 --> 00:03:54,200 ‫and Amazon S3 and then we're good to go, 100 00:03:54,200 --> 00:03:57,160 ‫and when you're ready, just click on create build project. 101 00:03:57,160 --> 00:03:58,850 ‫And now let's run a build, 102 00:03:58,850 --> 00:04:00,700 ‫so I click on Start Build, 103 00:04:00,700 --> 00:04:01,533 ‫and then say, okay, 104 00:04:01,533 --> 00:04:03,510 ‫I'm going to start a new build, 105 00:04:03,510 --> 00:04:05,120 ‫the source looks correct, 106 00:04:05,120 --> 00:04:07,320 ‫and so on, click on Start Build, 107 00:04:07,320 --> 00:04:08,820 ‫and let's see what happens here. 108 00:04:08,820 --> 00:04:10,230 ‫So the status is in progress, 109 00:04:10,230 --> 00:04:12,200 ‫so let's just wait a little bit. 110 00:04:12,200 --> 00:04:15,210 ‫Okay, so as we can see, this build has failed. 111 00:04:15,210 --> 00:04:16,990 ‫How surprising, so what's happening? 112 00:04:16,990 --> 00:04:18,580 ‫We have the entire log right here 113 00:04:18,580 --> 00:04:20,870 ‫and we can look at the phase details as well, 114 00:04:20,870 --> 00:04:23,730 ‫but the error comes from DOWNLOAD_SOURCE, 115 00:04:23,730 --> 00:04:26,130 ‫which failed because YAML_FILE_ERROR: 116 00:04:26,130 --> 00:04:27,970 ‫YAML file does not exist, 117 00:04:27,970 --> 00:04:29,230 ‫and that's indeed true 118 00:04:29,230 --> 00:04:32,800 ‫because this is looking for a buildspec.yml 119 00:04:32,800 --> 00:04:34,840 ‫in my code commit repository, 120 00:04:34,840 --> 00:04:36,470 ‫but currently there's none. 121 00:04:36,470 --> 00:04:38,020 ‫So what we can do, 122 00:04:38,020 --> 00:04:39,940 ‫and what we'll do in the very next lecture 123 00:04:39,940 --> 00:04:43,730 ‫is go to that CodeCommit repository in here 124 00:04:43,730 --> 00:04:46,640 ‫and add the missing buildspec.yml, 125 00:04:46,640 --> 00:04:49,040 ‫so for that, I will see you in the next lecture.