‫Okay, so now let's get into CodeBuild
‫to see how we can use CodeBuild not to build this time
‫but to test our code in our CodePipeline.
‫So what do we want to test?
‫Well, if you look at our Beanstalk environment,
‫we really, really like that congratulations message.
‫I think we should have it,
‫and we want to test for this not ever leaving the screen,
‫so we never want congratulations to go away,
‫this is what we want to test for.
‫So for this, let's go to CodeBuild and get started.
‫We're going to create our first build project
‫and I will call it MyBuildProjects,
‫and the description is going to be
‫testing for congratulations.
‫So the idea is that we're going to have a script
‫that will test whether or not this congratulation word
‫are going to appear in our webpage.
‫So I'm going to scroll down
‫and for the source provider,
‫I'm going to choose CodeCommits
‫and the repository going to be my-nodejs-app.
‫So we can see here in the primary sources,
‫we can have S3, GitHub, Bitbucket,
‫and GitHub Enterprise for now,
‫and so as you can see, CodeBuild can be used
‫to test many different projects.
‫So we'll use my-nodejs-app,
‫we'll choose a branch,
‫and the branch is going to be the main branch,
‫and then we don't specify a commit ID,
‫that means we want to test the main branch at its latest.
‫Okay, that's great,
‫then I will scroll down and under environments,
‫I will choose a managed image or a custom image.
‫So the idea is that CodeBuild uses Docker in the backend
‫to create a testing environment,
‫and so we can use the managed images by AWS
‫to have the ready to use images
‫when we want to test for specific programming languages,
‫but if you want you to have your own programming environment
‫and your own testing environments,
‫you could provide your own custom image.
‫In terms of operating system,
‫it's recommended to use Ubuntu,
‫as you can see in this message,
‫so we use Ubuntu, and for the runtime,
‫we'll be using standard,
‫and the image, I'm going to use codebuild/standard:5.0,
‫but the rule of thumb is that if you see this video
‫and there's been new releases for this image, 6.0, 7.0,
‫please use the latest and it will make sure
‫that the code will work, okay?
‫Then the image version is
‫always used the latest image for this runtime version,
‫we'll use Linux,
‫and then we'll create a new service role
‫that will be used by this CodeBuild project.
‫The important thing you can see,
‫an interesting thing you can see is that
‫there are some additional configurations to this,
‫for example, we have timeouts where we can set
‫how long we want the default timeouts,
‫they must between five minutes and eight hours,
‫so this is good if you know
‫that the build can not last too long,
‫you should then set this to something very, very low.
‫The VPC is something very interesting,
‫you can select the VPC, and the CodeBuild project
‫will run the VPC for the the build from within the VPC,
‫and the idea is that you can access
‫your internal resources such as RDS databases and so on.
‫You can set how big you want your compute power to be
‫for this testing image, we will choose the lowest.
‫We can specify environment variables
‫that can come from different places,
‫the Parameter store, Secrets Manager,
‫or just be Plaintext,
‫and we can specify a file system.
‫Now, the most important thing from an exam perspective
‫is that now we have the buildspec configuration
‫and we need to use a buildspec file
‫to specify how we want to build our project in CodeBuild,
‫and as you can see, we have a buildspec name as optional,
‫and that means that by default,
‫CodeBuild will look for a file named buildspec.yml
‫in the source code root directory.
‫So the idea is really, you want to remember
‫that buildspec.yml is the name of the file
‫and it's placed at the source code root directory.
‫Okay, so we won't specify anything here,
‫we'll just use a buildspec file.
‫I will scroll down,
‫and then for Artifacts is do you want to create artifacts,
‫for example, pushing a Docker image to Amazon ECR,
‫no, and we could push it to Amazon S3 as well
‫if you wanted to, but I will choose no artifacts.
‫And then for logging, we can have CloudWatch
‫and Amazon S3 and then we're good to go,
‫and when you're ready, just click on create build project.
‫And now let's run a build,
‫so I click on Start Build,
‫and then say, okay,
‫I'm going to start a new build,
‫the source looks correct,
‫and so on, click on Start Build,
‫and let's see what happens here.
‫So the status is in progress,
‫so let's just wait a little bit.
‫Okay, so as we can see, this build has failed.
‫How surprising, so what's happening?
‫We have the entire log right here
‫and we can look at the phase details as well,
‫but the error comes from DOWNLOAD_SOURCE,
‫which failed because YAML_FILE_ERROR:
‫YAML file does not exist,
‫and that's indeed true
‫because this is looking for a buildspec.yml
‫in my code commit repository,
‫but currently there's none.
‫So what we can do,
‫and what we'll do in the very next lecture
‫is go to that CodeCommit repository in here
‫and add the missing buildspec.yml,
‫so for that, I will see you in the next lecture.