Trying Out the New "Host Kernel Selection" Feature for AWS CodeBuild On-Demand Builds

Trying Out the New "Host Kernel Selection" Feature for AWS CodeBuild On-Demand Builds

AWS CLI v2.35.13 adds a hostKernel parameter to CodeBuild on-demand builds, with LINUX_KERNEL_4, LINUX_KERNEL_6 or LINUX_KERNEL_LATEST. I ran 16 builds (4 environments × 4 patterns) to check default behavior and Container/EC2 differences.
2026.07.03

This page has been translated by machine translation. View original

Introduction

On June 30, 2026, AWS CodeBuild began allowing you to select the host kernel for on-demand builds.

The following entry has been added to the CHANGELOG for 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 for each build with --host-kernel-override in start-build.

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

Why is host kernel selection necessary?

By default in CodeBuild (when hostKernel is not specified), Amazon Linux 2 (kernel 4.14) is used as the host kernel. However, Amazon Linux 2 reached EOL on June 30, 2026.

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

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

Item Before (hostKernel not specified) New (hostKernel specified)
Host kernel selection Not possible (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

Setting values

Setting 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 testing, it returned 6.1, the same as LINUX_KERNEL_6. The behavior of automatically following newer kernels is undocumented

Verification details

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

Test 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

I ran builds specifying the host kernel for each pattern with --host-kernel-override. The following is an example specifying LINUX_KERNEL_6 in 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 the content of /etc/os-release. For EC2 environments, I also checked /etc/os-release.

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 are the results for LINUX_CONTAINER / LINUX_EC2 (x86_64). The behavior pattern was the same 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 LINUX_KERNEL_6 is specified with 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 LINUX_KERNEL_4 is specified with 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 (not specified) behavior

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

What LINUX_KERNEL_LATEST actually is

As of now (July 2026), uname -r for LINUX_KERNEL_LATEST and LINUX_KERNEL_6 was the same 6.1.174-217.345.amzn2023 series. For both x86_64 and aarch64, LATEST follows 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 stated in the official documentation.

Behavior differences between Container and EC2 environments

In the Container environment, /etc/os-release inside the container was always Amazon Linux 2023 regardless of the hostKernel setting. Although the image names include amazonlinux2, the contents of the 5.0 / 3.0 images used here are AL2023. On the other hand, since uname -r returns the host kernel version, I could confirm the difference in host kernels even from inside the container.

In the EC2 environment, the host OS itself switches depending on the hostKernel setting. With LINUX_KERNEL_4 it is Amazon Linux 2, and with LINUX_KERNEL_6 it is Amazon Linux 2023. Because the OS differs, you need to pay attention to build script compatibility.

Summary

The hostKernel parameter now lets you explicitly select the host kernel for CodeBuild on-demand builds. By default (not specified) and with LINUX_KERNEL_4, AL2 kernel 4.14 is used, so in light of the AL2 EOL, I recommend specifying LINUX_KERNEL_6 or LINUX_KERNEL_LATEST 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 keep up when the kernel generation changes. In EC2 environments, the host OS itself switches, so it is prudent to first check compatibility with AL2023 using LINUX_KERNEL_6 and, if there are no problems, adopt it as is.

Share this article

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