developer-tools

AWS CodeBuild

Managed, pay-per-minute CI build compute — it clones your source, runs your build and tests in a throwaway container, and uploads the artifacts. Here's what CodeBuild is good for, what it costs, how it connects to the rest of your pipeline, and the mistakes Design Beaver catches as you draw.

Updated July 14, 2026

What CodeBuild is

CodeBuild is a fully managed continuous-integration build service. You create a “project” that points at a source — CodeCommit, S3, GitHub, GitLab, or Bitbucket — and hand it a buildspec, a YAML file of shell commands. On each build it spins up a fresh, ephemeral container, clones the source, runs your compile/test/package steps, uploads the resulting artifacts (usually to S3), and throws the container away. There are no build servers to provision, patch, or scale, and you pay per build-minute for the compute size you pick.

It’s specifically a build service, not a deploy service: it produces artifacts. Getting those artifacts onto servers is CodeDeploy’s or a pipeline deploy action’s job. Design Beaver models CodeBuild as an external, API-accessed build node and validates as you draw — so it knows the source, artifact, and IAM edges a build actually needs, and which ones don’t exist.

When to use CodeBuild (and when not to)

Reach for CodeBuild when you want managed, ephemeral CI compute and don’t want to run and patch your own build fleet. It fits the build/test stage of an AWS pipeline that plugs straight into CodePipeline, and it fits bursty workloads where you’d rather pay per build-minute than keep an always-on build box idle between commits. It also gives you a build that runs under an IAM role and can optionally reach private resources inside your VPC during tests.

Don’t reach for it when you only need to deploy already-built artifacts — that’s CodeDeploy or a pipeline deploy action, not a build service. Skip it if you want a full end-to-end release orchestrator with stages and approvals, because that’s CodePipeline and CodeBuild is one action inside it. It’s also the wrong choice if your team is already standardized on an external CI like GitHub Actions or GitLab CI and doesn’t want a second build system, or if the workload is a long-running service rather than a finite build job — CodeBuild containers are ephemeral and time-boxed.

Variants: compute model, not instance sizes

The choice that matters up front isn’t a compute SKU — it’s how the build compute is provisioned and billed. CodeBuild also offers many prebuilt images, GPU compute, and per-size tiers not listed here.

OptionWhat it is
On-demand (managed) computedefaultThe default. CodeBuild provisions a fresh managed build container for each build from a warm pool and bills per build-minute for the compute size you select. No capacity to reserve or manage; best for typical bursty CI workloads.
Reserved-capacity fleetsA dedicated fleet of build machines kept warm and reserved for your account, billed for the reserved capacity rather than purely per build-minute. Trades higher baseline cost for lower per-build start latency and consistent throughput at high, steady build volume.
Lambda computeRuns the build on AWS Lambda-based compute for very fast start-up and short builds, billed for the Lambda-style runtime. Suited to small, quick jobs where cold-start latency matters more than raw build power; has tighter resource/runtime limits than the container compute types.

CodeBuild pricing in plain English

You pay per build-minute for on-demand builds at a rate that scales with the compute size, and nothing when no build runs; reserved-capacity fleets and Lambda compute are billed on their own models. Cache dependencies and layers so they aren’t rebuilt every run, pick the smallest compute size that works, and prefer ARM/Graviton compute where your toolchain supports it.

You pay per build-minute for on-demand builds, priced by the compute type/size you select (larger compute = higher per-minute rate); there's no charge when no build is running. Reserved-capacity fleets and Lambda compute are billed on their own models. Additional AWS costs (S3 storage for artifacts/cache, data transfer, any VPC/NAT for VPC-connected builds) are separate.

OptionRepresentative rate
on-demandLinux general1.small ~$0.005 per build-minute; general1.medium ~$0.01; general1.large ~$0.02; larger/GPU sizes cost substantially more per minute. ARM and Lambda compute are priced separately.
reserved-capacityReserved-capacity fleets are billed for the reserved machines by the hour, not per build-minute; verify current rates on the pricing page.
lambda-computeLambda compute is billed on its own per-minute model, separate from on-demand build compute; verify current rates on the pricing page.

Free tier

  • Historically 100 build-minutes/month of general1.small on-demand compute in the AWS Free Tier; confirm current terms on the pricing page.

Keeping the bill down

  • Enable a build cache (S3 or local) so dependencies and layers aren't re-downloaded/rebuilt every build, cutting build-minutes
  • Pick the smallest compute size that meets the build's needs — you pay per minute at a rate that scales with compute size
  • Prefer ARM/Graviton build compute where your toolchain supports it — generally cheaper per minute than x86
  • For very short jobs, consider Lambda compute to avoid paying for container start-up time; for high steady volume, evaluate reserved-capacity fleets

us-east-1, Linux on-demand compute (rates vary by region, compute type, OS, and architecture). Rates as of 2026-07. Verify at the official pricing page before using for real cost estimates — these numbers are not kept in sync with AWS pricing changes and depend heavily on compute size, region, and build duration.

How CodeBuild connects to other services

CodeBuild’s build container runs under a service role you attach to the project, and almost every AWS connection it makes is that role’s credentials being used automatically inside the build. The recurring theme is to grant the service role the specific, scoped actions a build needs, never to bake access keys into the buildspec. Design Beaver models each of these edges — including the easy-to-miss ones, like the sts:GetServiceBearerToken that CodeArtifact logins require on top of the codeartifact:* actions.

  • CodeCommitsecurity

    CodeBuild clones the source code (and buildspec) for the project from a CodeCommit repository at the start of a build

    IAM:codecommit:GitPull

  • S3security

    CodeBuild uploads build output artifacts to an S3 bucket, reads/writes an S3 build cache, and can pull the source itself from an S3 object (zip or folder)

    IAM:s3:GetObjects3:GetObjectVersions3:PutObjects3:GetBucketAcls3:GetBucketLocation

  • ECRsecurity

    CodeBuild pulls a custom build-environment image from a private ECR repository to run the build in, and/or builds a Docker image during the build and pushes it back to ECR

    IAM:ecr:GetAuthorizationTokenecr:BatchCheckLayerAvailabilityecr:GetDownloadUrlForLayerecr:BatchGetImageecr:InitiateLayerUploadecr:UploadLayerPartecr:CompleteLayerUploadecr:PutImage

  • CodeArtifactsecurity

    During a build, CodeBuild authenticates to a CodeArtifact repository to pull private packages (npm, pip, Maven, NuGet) — and optionally publish built packages back to it

    IAM:codeartifact:GetAuthorizationTokencodeartifact:GetRepositoryEndpointcodeartifact:ReadFromRepositorysts:GetServiceBearerToken

  • Secrets Managersecurity

    CodeBuild pulls sensitive build values — private-registry credentials, API tokens, signing keys — from Secrets Manager instead of storing them as plaintext environment variables

    IAM:secretsmanager:GetSecretValue

  • CodePipeline invokes a CodeBuild project as a Build or Test action in a stage — the standard way CI runs inside an AWS release pipeline. CodePipeline hands CodeBuild the stage's input artifact and collects its output artifact for the next stage

What CodeBuild can’t connect to

Some edges look reasonable on a canvas but don’t exist in AWS. Design Beaver flags them instead of letting you draw a diagram that can’t be built.

  • CodeBuild and CodeDeploy do not connect directly — CodeBuild produces build artifacts (typically to S3) and CodeDeploy consumes an artifact to deploy it, but nothing calls from one to the other. The handoff is orchestrated by CodePipeline, which takes CodeBuild's output artifact and feeds it to a CodeDeploy deploy action. Draw the edges through CodePipeline (or the shared S3 artifact bucket), not as a CodeBuild-to-CodeDeploy line.

Anti-patterns Design Beaver catches

These are the CodeBuild mistakes that pass a diagram review but bite in production — the ones the validation engine flags as you draw.

Storing secrets (registry passwords, API tokens, signing keys) as PLAINTEXT environment variables on the CodeBuild project

Why it breaksPLAINTEXT environment variables are displayed in clear text in the CodeBuild console and via the AWS CLI, and can leak into build logs — anyone with read access to the project or a build sees them

Do this insteadUse SECRETS_MANAGER- or PARAMETER_STORE-type environment variables (or a secrets-manager reference in the buildspec) so the value is fetched at build time and never stored on the project in the clear

Giving the CodeBuild service role broad wildcard permissions (e.g. s3:*, ecr:*, or Action: * on Resource: *) to make a build 'just work'

Why it breaksThe build container runs arbitrary commands from the buildspec and source repo; an over-privileged service role means a compromised or malicious build can reach far beyond what it needs

Do this insteadScope the service role to the specific actions and resources the build uses — the concrete pull/put actions on the specific buckets, repos, and secrets (as in the per-edge iamActions here)

Running Docker builds without privileged mode and then being surprised the build can't reach the Docker daemon

Why it breaksdocker build / docker push inside a CodeBuild container needs the Docker daemon, which requires the project's privileged flag to be enabled — without it, Docker commands fail

Do this insteadEnable privileged mode on projects that build container images (and prefer VPC endpoints / ECR access scoped tightly), or use a build approach that doesn't need a nested Docker daemon

Gotchas that bite in production

  • Plaintext env vars leak. PLAINTEXT-type environment variables show up in clear text in the console and CLI and can end up in build logs. Anything sensitive belongs in a SECRETS_MANAGER or PARAMETER_STORE env var or a buildspec secrets reference, not a plaintext project variable.
  • Docker builds need privileged mode. docker build and docker push inside a CodeBuild container require the Docker daemon, which only runs when the project’s privileged flag is on. Without it, Docker commands just fail.
  • The service role is a real attack surface. The build runs arbitrary commands from your buildspec and source, so a role with s3:*, ecr:*, or Action: * lets a compromised build reach far past what it needs. Scope it to the concrete actions and resources each build actually uses.
  • CodeArtifact needs an STS permission too. It’s easy to grant the codeartifact:* actions and forget sts:GetServiceBearerToken — without it, GetAuthorizationToken fails and the package-manager login won’t work.
  • VPC access is optional and per-project. CodeBuild isn’t subnet-resident, but you can attach a build to a VPC to reach private resources like a test database. That’s a project setting with its own subnet, security-group, and route considerations — and a NAT path if the build needs the internet — not the default.

Further reading

Frequently asked questions

When should you use AWS CodeBuild?
Use CodeBuild when you want managed, ephemeral CI build compute and don't want to run or patch your own build servers — compiling code and running tests on every commit, building a Docker image and pushing it to ECR, or any bursty, finite scripted job. It's the wrong tool if you only need to deploy already-built artifacts (that's CodeDeploy or a pipeline deploy action), if you want a full release orchestrator with stages and approvals (that's CodePipeline), or if you need to host a long-running service — CodeBuild containers are ephemeral and time-boxed.
How much does AWS CodeBuild cost?
On-demand builds bill per build-minute at a rate that scales with the compute size you pick, and nothing is charged when no build runs. Reserved-capacity fleets and Lambda compute are billed on their own models. Watch the other costs too — S3 storage for artifacts and cache, data transfer, and any NAT/VPC charges for VPC-connected builds. Verify the current per-minute figures on the official pricing page before estimating a real bill.
Can AWS CodeBuild connect to CodeDeploy?
No — not directly. CodeBuild produces build artifacts and CodeDeploy consumes an artifact to deploy it, but nothing calls from one to the other. The handoff is orchestrated by CodePipeline, which takes CodeBuild's output artifact and feeds it to a CodeDeploy deploy action. Design Beaver flags a direct CodeBuild → CodeDeploy edge as invalid; draw it through CodePipeline or the shared S3 artifact bucket.
Does AWS CodeBuild need privileged mode for Docker builds?
Yes. Running docker build or docker push inside a CodeBuild container requires the Docker daemon, which only runs when the project's privileged flag is enabled. Without it, Docker commands fail. Enable privileged mode on any project that builds container images.

Validate your CodeBuild architecture as you draw

Design Beaver checks your AWS design in real time — missing queues, invalid connections, and security anti-patterns, caught before you ship. It’s live in beta, free, and runs in your browser with no account.

Open the app →

Prefer email? Get new features in your inbox:

← All supported services