- AWS Automation Cookbook
- Nikit Swaraj
- 588字
- 2021-07-02 23:00:43
How it works...
- Open the AWS console and go to the AWS CodeBuild service. You will get the CodeBuild console. Click on Get started:

- You will get a page where you have to fill all the details that I mentioned earlier. The page will look as follows:

- We will mention the Project name as CB-Build-Book in the Configure your project section:

- In the Source section, choose AWS CodeCommit as Source provider and select the Repository name where you have migrated the book application. In my case, the AWS CodeCommit repository name, where the book application code resides, is CB-MAVEN-Book:

- In the Environment section, Environment image will be Use an image managed by AWS CodeBuild. The Operating System will be Ubuntu, Runtime will be Java, Version will be aws/codebuild/java:openjdk8, Build specification will be Insert build commands and Build command will be mvn install:

- Now in the Artifacts section, we have to use AWS S3 to store the build output. So, Artifact type will be Amazon S3. The Artifacts name will be book, Bucket name where you want to put the artifact; in my case, its awsstar-s3 and the Output files field will contain the file name which will be the build output, in my case, it's target/books.war (you should know in what way the build output will come):

- Now, Service role is the most important section over here, which allows AWS Codebuild to access another AWS resources such as CodeCommit and S3. In the initial stage, you can create a new service role. Else, you can create a new IAM Role, which will have the following policy document:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "CloudWatchLogsPolicy",
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": [
"*"
]
},
{
"Sid": "CodeCommitPolicy",
"Effect": "Allow",
"Action": [
"codecommit:GitPull"
],
"Resource": [
"*"
]
},
{
"Sid": "S3GetObjectPolicy",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:GetObjectVersion"
],
"Resource": [
"*"
]
},
{
"Sid": "S3PutObjectPolicy",
"Effect": "Allow",
"Action": [
"s3:PutObject"
],
"Resource": [
"*"
]
}
]
}
- Once we create the policy, we need to create the IAM role, in which AWS Service role will be AWS CodeBuild and we will attach the newly created policy with the IAM role. Post that, we have to select a service role in the AWS CodeBuild Service Role section:

- In the Advanced section, we can tweak the compute settings and pass the environment variables, but at this moment, it is not required.
- Finally, we click on Continue and review the configuration:

- Once you are done reviewing, then click on Save and Build. We will be asked which branch we want to build:

- Once you select the master, the source version will show up automatically. Then, click on >Start Build. We will see that the build process will start:

- We will see different phases of Build as well:

- In Build details section, we can see Output artifacts. When we click on the Build artifacts, we will be redirected to the S3 bucket, where our artifact will reside after the successful build:

- The following diagram shows the artifact in the S3 bucket:

- When you click on book, you will get a folder called target. Click on the target folder to get the books.war file:

- Now, we can download books.war into the server or machine, and copy books.war to your webserver webapp directory and restart the webserver and access it from the web browser:

推薦閱讀
- 我的J2EE成功之路
- 智能傳感器技術與應用
- Julia 1.0 Programming
- 返璞歸真:UNIX技術內(nèi)幕
- VB語言程序設計
- 觸控顯示技術
- Learn CloudFormation
- Grome Terrain Modeling with Ogre3D,UDK,and Unity3D
- Working with Linux:Quick Hacks for the Command Line
- Learning Apache Apex
- Linux系統(tǒng)管理員工具集
- 青少年VEX IQ機器人實訓課程(初級)
- Mastering Predictive Analytics with scikit:learn and TensorFlow
- 工廠電氣控制設備
- Oracle Blockchain Quick Start Guide