AWS Automation Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

  1. Go to the AWS Console and click on the AWS CodeBuild Service. After that, click on Create project.
  2. We will get a page where we have to fill all the details that I have mentioned in the Getting ready section in this recipe. The page will look like as follows:
  1. We will mention the Project name as CB-NodeJS-BS in the Configure your project section:
  1. In the Source section, choose AWS CodeCommit as Source provider. Select the repository name where you migrated the book application. In my case, the AWS CodeCommit repository name where the book application code resides is CB-NODEJS-Site:
  1. In the Environment section, Environment image will be Image managed by AWS CodeBuild. The OS will be Ubuntu, Runtime will be Node.js, Version will be aws/codebuild/nodejs:4.3.2, Build specification will be Use the buildspec.yml in the source code root directory:
  1. Now in the Artifact section, we use AWS S3 to store the build output. So, Artifact type will be Amazon S3. The Artifacts name will be Nodejs-bs; Bucket name is where you put the artifact. In my case, its awsstar-s3:
  1. Now choose any existing service role, which will allow AWS CodeBuild to access any other AWS resources:
  1. In advance, we can tweak the compute settings and pass the environment variables; but at this moment, it is not required.
  2. Finally, we click on Continue and review the configuration:
  1. Once you are done reviewing, then click on Save and Build. We will be asked which branch we want to build. In the advanced options, we will be asked regarding the Artifact Package, which we will put as zip. Then, click on start build:
  1. We will see that the build process has been started and succeeded in a minute:
  1. We will see different phases of the build as well:
  1. In the Build details section, we can see the output artifact; when we click on Build artifacts, we will be redirected to the S3 bucket where our artifact will reside after the successful build:
  1. The following screenshot shows the artifact in the S3 bucket:
  1. Now, download the zip file and unzip it to your production machine and place it on the proper path where webserver can read it. After that, restart the webserver and try to access the page:

In both the preceding examples, we saw how we can work with AWS CodeBuild either using build commands in the console or using the buildspec.yml file.