I tried out the new "host kernel selection" feature for AWS CodeBuild on-demand builds

I tried out the new "host kernel selection" feature for AWS CodeBuild on-demand builds

In AWS CLI v2.35.13, the hostKernel parameter was added to CodeBuild on-demand builds. You can choose from LINUX_KERNEL_4 / LINUX_KERNEL_6 / LINUX_KERNEL_LATEST. We ran 16 builds (4 environments × 4 patterns) and verified the default behavior and differences between Container and EC2 environments.
2026.07.03

This page has been translated by machine translation. View original

Introduction

On June 30, 2026, AWS CodeBuild introduced the ability to select the host kernel for on-demand builds.

The following entry has been added to the CHANGELOG of AWS CLI v2.35.13:

2.35.13

api-change:codebuild: Adds support for host kernel selection for on-demand builds.

You can specify a default value with environment.hostKernel in the project settings, and override it per build using --host-kernel-override in start-build.

https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codebuild/start-build.html

Why host kernel selection is needed

In CodeBuild's default behavior (when hostKernel is not specified), Amazon Linux 2 (kernel 4.14) is used as the host kernel. However, Amazon Linux 2 reached its EOL on June 30, 2026.

https://dev.classmethod.jp/articles/free-amazon-linux-2-bird/

Previously, even if you specified latest for the AMI in CodeBuild EC2 compute, an AL2 host would launch, and there was no way to select an AL2023 host. The hostKernel parameter changes this as follows:

Item Before (hostKernel not specified) After (hostKernel specified)
Host kernel selection Not available (implicitly AL2 kernel 4.14) Choose from LINUX_KERNEL_4 / LINUX_KERNEL_6 / LINUX_KERNEL_LATEST
Host OS for EC2 compute Always AL2 AL2 or AL2023 depending on the setting
Host kernel for Container compute Always kernel 4.14 kernel 4.14 or 6.1 depending on the setting

Configuration values

Value Host kernel Notes
LINUX_KERNEL_4 kernel 4.14 (Amazon Linux 2) Same as the previous behavior
LINUX_KERNEL_6 kernel 6.1 (Amazon Linux 2023) AL2023-based host
LINUX_KERNEL_LATEST Latest kernel At the time of verification, returned the same 6.1 as LINUX_KERNEL_6. Auto-follow behavior is undocumented

Verification details

We ran 16 patterns: 4 environment types × 4 hostKernel settings.

Verification environment

  • Region: ap-northeast-1
  • Compute type: BUILD_GENERAL1_SMALL
  • Source: NO_SOURCE (inline buildspec)
  • AWS CLI: v2.35.15

Environment types and images used:

Environment type Architecture Image
LINUX_CONTAINER x86_64 aws/codebuild/amazonlinux2-x86_64-standard:5.0
ARM_CONTAINER aarch64 aws/codebuild/amazonlinux2-aarch64-standard:3.0
LINUX_EC2 x86_64 aws/codebuild/ami/amazonlinux-x86_64-base:latest
ARM_EC2 aarch64 aws/codebuild/ami/amazonlinux-arm-base:latest

Verification method

Builds were executed by specifying the host kernel for each pattern using --host-kernel-override. The following is an example of specifying LINUX_KERNEL_6 for the LINUX_CONTAINER environment.

aws codebuild start-build \
  --project-name kernel-test-linux-container \
  --host-kernel-override LINUX_KERNEL_6 \
  --buildspec-override 'version: 0.2
phases:
  build:
    commands:
      - uname -r
      - uname -a
      - cat /etc/os-release'

Verification results

The host OS column for Container environments is determined from uname -r. The container OS is from the contents of /etc/os-release. For EC2 environments, /etc/os-release was also checked.

Container environment

hostKernel uname -r Host OS Container OS
LINUX_KERNEL_4 4.14.355-282.733.amzn2.x86_64 Amazon Linux 2 Amazon Linux 2023
LINUX_KERNEL_6 6.1.174-217.345.amzn2023.x86_64 Amazon Linux 2023 Amazon Linux 2023
LINUX_KERNEL_LATEST 6.1.174-217.345.amzn2023.x86_64 Amazon Linux 2023 Amazon Linux 2023
Not specified 4.14.355-282.733.amzn2.x86_64 Amazon Linux 2 Amazon Linux 2023

EC2 environment

hostKernel uname -r Host OS
LINUX_KERNEL_4 4.14.355-282.733.amzn2.x86_64 Amazon Linux 2
LINUX_KERNEL_6 6.1.174-217.345.amzn2023.x86_64 Amazon Linux 2023
LINUX_KERNEL_LATEST 6.1.174-217.345.amzn2023.x86_64 Amazon Linux 2023
Not specified 4.14.355-282.733.amzn2.x86_64 Amazon Linux 2

The above results are for LINUX_CONTAINER / LINUX_EC2 (x86_64). The same behavior patterns were observed for ARM_CONTAINER / ARM_EC2 (aarch64).

ARM environment results (all 8 patterns)
Environment type hostKernel uname -r Host OS Container OS
ARM_CONTAINER LINUX_KERNEL_4 4.14.355-284.735.amzn2.aarch64 Amazon Linux 2 Amazon Linux 2023
ARM_CONTAINER LINUX_KERNEL_6 6.1.174-217.345.amzn2023.aarch64 Amazon Linux 2023 Amazon Linux 2023
ARM_CONTAINER LINUX_KERNEL_LATEST 6.1.174-217.345.amzn2023.aarch64 Amazon Linux 2023 Amazon Linux 2023
ARM_CONTAINER Not specified 4.14.355-284.735.amzn2.aarch64 Amazon Linux 2 Amazon Linux 2023
ARM_EC2 LINUX_KERNEL_4 4.14.355-284.735.amzn2.aarch64 Amazon Linux 2
ARM_EC2 LINUX_KERNEL_6 6.1.174-217.345.amzn2023.aarch64 Amazon Linux 2023
ARM_EC2 LINUX_KERNEL_LATEST 6.1.174-217.345.amzn2023.aarch64 Amazon Linux 2023
ARM_EC2 Not specified 4.14.355-284.735.amzn2.aarch64 Amazon Linux 2

Log output examples

When specifying LINUX_KERNEL_6 for LINUX_CONTAINER:

uname -r: 6.1.174-217.345.amzn2023.x86_64
uname -a: Linux b52a676ce38d 6.1.174-217.345.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Jun  1 16:38:11 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
/etc/os-release: Amazon Linux 2023.12.20260611

When specifying LINUX_KERNEL_4 for LINUX_EC2:

uname -r: 4.14.355-282.733.amzn2.x86_64
uname -a: Linux ip-xx-xx-xx-xxx.ap-northeast-1.compute.internal 4.14.355-282.733.amzn2.x86_64 #1 SMP Mon Jun 1 08:18:47 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
/etc/os-release: Amazon Linux 2 (SUPPORT_END=2026-06-30)

Discussion

Default (unspecified) behavior

When hostKernel was not specified for all environment types, the host kernel was kernel 4.14 (Amazon Linux 2). This is the same behavior as the previous CodeBuild, and the default behavior has not changed before or after this feature addition.

The actual behavior of LINUX_KERNEL_LATEST

As of the current time (July 2026), the uname -r output for LINUX_KERNEL_LATEST and LINUX_KERNEL_6 were both the same 6.1.174-217.345.amzn2023 series. For both x86_64 and aarch64, LATEST shows the same behavior pattern as LINUX_KERNEL_6.

It is presumed that LATEST is intended to automatically follow future kernel updates, but this behavior is not explicitly documented in the official documentation.

Behavioral differences between Container and EC2 environments

In Container environments, regardless of the hostKernel setting, /etc/os-release inside the container was always Amazon Linux 2023. Although the image name contains amazonlinux2, the contents of the 5.0 / 3.0 images used this time are AL2023. On the other hand, since uname -r returns the host kernel version, it was possible to confirm the difference in host kernels from within the container.

In EC2 environments, the host OS itself switches depending on the hostKernel setting. LINUX_KERNEL_4 uses Amazon Linux 2, and LINUX_KERNEL_6 uses Amazon Linux 2023. Since the OS differs, care must be taken regarding the compatibility of build scripts.

Summary

The hostKernel parameter now allows explicit selection of the host kernel for CodeBuild on-demand builds. Since AL2 kernel 4.14 is used by default (unspecified) and with LINUX_KERNEL_4, and given that AL2 has reached its EOL, specifying LINUX_KERNEL_6 or LINUX_KERNEL_LATEST is recommended for new projects.

In Container environments, the container image itself does not change with the hostKernel setting, so specifying LINUX_KERNEL_LATEST should make it easier to adapt to future kernel generation changes. In EC2 environments, the host OS itself switches, so it is prudent to first verify AL2023 compatibility with LINUX_KERNEL_6, and if there are no issues, adopt it as-is.

Share this article

AWSのお困り事はクラスメソッドへ