CodeBuild with the Amazon Linux 2 environment

Posted in Devops, published on

Tags: AWS CICD Build Automation Linux

If you're using AWS CodeBuild to build your software, there's a gotcha if you're using the new Amazon Linux 2 environment. If you use your old buildspec.yml you will run into an error

Phase context status code: YAML_FILE_ERROR Message: This build image requires selecting at least one runtime version.

Previous versions of CodeBuild had a different environment configuration that allowed you to select an environment image like python:3.6.6. This environment specified your runtime. But the new CodeBuild version makes you select either Amazon Linux 2 or Ubuntu as environment. Note that this doesn't specify the runtime, just the base operating system your build will be using. Specifying the runtime now happens in your buildspec.yml file:

version: 0.2

phases:
    install:
        runtime-versions:
            python: 3.7
    build:
        commands:
            - echo "building stuff..."

Your existing CodeBuild projects will not be affected, they will continue to work. But any new projects you create will require you to specify the new environment, and specify the runtime in your buildspec.yml file.

More information about the runtime-versions parameter can be found here: https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#runtime-versions-buildspec-file.