‫So now let's talk about code builds.
‫So code build is actually takes a source of code.
‫For example, code commit, Amazon, S3, Bitbucket or GitHub.
‫And then in that source there will be some build instructions.
‫Now, from an exam perspective, you need to know the name of that file.
‫So it's buildspec.yml and that file needs to leave at the root of your code.
‫And I will show this what it means in the hands on.
‫Or you can also insert these instructions in the console.
‫But the best practice is to use Buildspec.yml and this is what the exam will test you on.
‫So once the application is built, the output logs can be stored into Amazon, S3 and Cloudwatch logs
‫for later analysis.
‫You can use metrics to Cloudwatch metrics to look at the build statistics Eventbridge to detect failed
‫builds and trigger notifications.
‫Cloudwatch alarms.
‫In case you have too many failures, for example.
‫And then the build projects themselves can be and this is a bit confusing, define either within codebuild
‫of course, or also within Codepipeline.
‫But Codepipeline can also invoke an existing code build build project.
‫So if we look at code build, what can I test?
‫Well, if you have a Java ruby python, go NodeJS android.
‫Net core PHP application.
‫Then there is a pre-built image for you to run your test in code build and if you want to have any other
‫environments well, you can extend a Docker image and by extending it you can test for whatever language
‫you want.
‫But again, this is up to you to support your own environment.
‫So how does code build works?
‫Well, we have our code and in this example it's in code commit.
‫So we have our source code, a bunch of files.
‫And then there is this very important file that lives at the top of your repo, which is buildspec.yml
‫now could build, is going to fetch this code and then Codebuild itself will have to have a container.
‫So as I said, there is going to be a build environment.
‫So Java go and so on and this container is going to load all the source code and the buildspec.yml and
‫it's going to run all the instructions that are inserted into this Buildspec.yml file.
‫Now to build this container, our code build will pull a Docker image.
‫So either it's prepackaged by AWS for the environments I just told you before or you provide your own
‫Docker image to run whatever code you need.
‫Okay, so code build will run all the instructions from buildspec.yml and sometimes they can be quite
‫lengthy.
‫So there is a feature in code build to be able to cache a bunch of files in S3 buckets.
‫If you want to reuse some files from build to build.
‫Okay, this is an optimization, but there is a way for you to cache some files.
‫This is optional though.
‫Then all the logs are going to be into cloudwatch logs and Amazon S3 if you enable it.
‫And then once Codebuild is done to build your code or even test your code, it can produce some artifacts
‫and these artifacts will be extracted out of the container, put into an S3 bucket.
‫And this is where you can find your final outputs of code build.
‫So the Buildspec.yml file is super important.
‫This is what it looks like.
‫We'll have a look at it obviously in this course.
‫But so some very important things that the Buildspec.yml file must be at the root of your code.
‫So at the very, very top of your code directory environment allows you to define some environment variables
‫for the execution of buildspec.yml.
‫So you have variables that can be plain text or you can pull them directly from the SSM parameter store,
‫or you can pull secrets directly from Secrets Manager.
‫This will allow you, for example, to get a password or for a database and so on that are clearly from
‫some places that of course you wouldn't want to store these passwords in plain text into a file like
‫Buildspec.yml.
‫Then phases, which is actually going to define what code build is going to be doing.
‫So it's a bunch of installs, for example, to say, Hey, what commands we want to do to install some
‫pre necessary packages and so on pre-build, which is the commands to execute just before the build
‫build the actual build commands very important.
‫Then we have post build, which are the finishing touches.
‫For example, once it's built, maybe creates a good zip output and so on.
‫And then the artifacts.
‫So which files at the Docker container should be extracted and sent into Amazon S3 There's also going
‫to be encrypted.
‫And finally there's this cache block to say which files, which dependencies are going to be cached
‫in Amazon.
‫S3 for for speeding up the future builds.
‫Okay.
‫So this is called build a high level.
‫But from this file, just remember, you know, to me the most important thing is the name of the file
‫where it sits.
‫And again, just understand the general idea of how Codebuild works and you should be good to go.
‫Now, code build is something that runs on the cloud, but it is possible for you if you need to do
‫some deep troubleshooting beyond the logs to run code, build locally on your desktop.
‫First, you need to install Docker obviously, and then you leverage the Codebuild agent.
‫The instructions are here and this allows you to reproduce a codebuild build on your machine and really
‫see what's going on when you have failures.
‫Also could build, can be launched within a VPC.
‫So by default your could build containers.
‫Instances are launched outside your VPC.
‫That means that it's going to run fine, but it cannot access some resources that are within your VPC.
‫So you can specify a VPC configuration for Codebuild with a VPC, ID, some subnet IDs, security group
‫IDs and so on.
‫And then thanks to this, then could build containers, we'll be able to access resources in your VPC,
‫such as RDS, elasticache, EC2 instances, albs, and so on.
‫So in this example I have RDS database in a private subnet in my VPC and I can directly launch my codebuild
‫container in here and then my codebuild container could access my database instance if he needed to.
‫So the use case is to have codebuild inside your VPC is to do integration testing data query to talk
‫to internal load balancers and so on.
‫So that's it for Codebuild.
‫I hope you liked it.
‫And let's go into the next lecture for some practice.