June 2024

Package an App with AWS CodeBuild

In this project, I learned how to:

✅ Steps completed from previous project sections:

Step 1: Setting up a web app and IDE in the Cloud

Step 2: Create a Repository in AWS CodeCommit

Step 3: Secure the project's dependencies with AWS CodeArtifact

⏭️ Step 4: Package an App with AWS CodeBuild

1. Set up an S3 bucket to store the WAR file

Key notes ✏️:

What is WAR file?

The build process will translate the app's code into machine code that computers (servers) can understand and run. Building includes the steps like compiling the code, running tests, and packaging the application. After successfully going through those steps, files called "build artifacts" will be created that packs up a bundle for the server to host the app. The bundle is called a WAR (Web Application Resource) file. When hosting, the server will "unzip" this WAR file get files and resources needed host your web app straight away.

2. Create a build project in CodeBuild

maven package flow

3. Modify the service role

The new service role created by CodeBuild only gave minimum permissions which by default does not include access to CodeArtifact repository. So here I attach the "codeartifact-nextwork-consumer-policy" that I created in CodeArtifact to the service role.

4. Create the buildspec.yml file

Key notes ✏️:

What is buildspec.yml for?

This file configures the commands that CodeBuild will run line by line to build the web app. Having a buildspec.yml file makes sure that every build follows the same steps and produces consistent results.

4. Start the build

5. Check the S3 bucket

The .zip file that contains the WAR file appears in the bucket. The build is done 🎉

In the next project (part four), I'm going to deploy the project based on the WAR file that CodeBuild produced.

Big thanks to @NextWork for setting up this engaging challenge!