My introduction to AWS CodeBuild was an error log sent to me by a software engineer. I saw in the logs a NestJS application, as indicated by the nest start
command in it.
I immediately recognized from the name of the AWS service (CodeBuild) and from the logs that this had to be a build system, similar to what you could achieve in GitHub Actions.
Well, a nest build
command was failing; however, it seemed to run successfully on the engineer's computer.
I needed to understand how CodeBuild was being triggered, and like most build systems, there ought to be a build config. I didn't find anything useful while browsing the AWS Console, so I looked at the root of the repo and found a buildspec.yml
. This had to be it.
Looking in the file, I found something that made sense:
version: 0.2
phases:
install:
commands:
- npm install
- npm install typescript
pre_build:
commands:
...
build:
commands:
...
post_build:
commands:
...
artifacts:
files:
- '**/*'
There must be some way to run this locally in a container, I thought, and true to that, I found that I could.
First, I pulled the Amazon Linux 2 image:
docker pull public.ecr.aws/codebuild/amazonlinux-x86_64-standard:4.0
Next, I pulled the agent (x86_64 version)
docker pull public.ecr.aws/codebuild/local-builds:latest
Afterwards, I downloaded a bash script into the root of the repository and made it executable:
$ curl -O https://raw.githubusercontent.com/aws/aws-codebuild-docker-images/master/local_builds/codebuild_build.sh
$ chmod +x codebuild_build.sh
Finally, I ran the script with the
./codebuild_build.sh -i public.ecr.aws/codebuild/amazonlinux-x86_64-standard:4.0 -a <output directory>
And then the logs came out just like I saw on the AWS Console.
After examing the logs and the application code, it was the typescript version that needed a change.
version: 0.2
phases:
install:
commands:
- npm install
- npm install typescript@5.5.4
...
Running the script one more time with this new buildspec.yml, there was no failure.
I made a PR, and that problem was fixed.
Pros of Debugging locally:
- Cost: AWS charges you for every build on AWS CodeBuild. Rerunning the CodeBuild with costs low.
- Velocity: You can make changes locally and test all within an IDE, skipping the need for commits, PR reviews, etc.
Cons of Debuigging locally:
- The Amazon Linux Image may be large and might pose a challenge in a low internet environment.
Top comments (0)