AWS CDK CodeBuild Construct Library (v1)

1.204.0 · active · verified Fri Apr 17

The `aws-cdk.aws-codebuild` package is part of the AWS Cloud Development Kit (CDK) v1, providing constructs for defining AWS CodeBuild resources programmatically in Python. It allows users to create, configure, and manage CodeBuild projects, build specifications, and associated resources. While AWS CDK v2 is the latest major version, v1 continues to receive maintenance updates for existing projects. Releases for CDK v1 often align with new AWS service features or bug fixes, typically on a weekly or bi-weekly cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a basic AWS CodeBuild project using AWS CDK v1. It creates a project with an inline build specification that prints a message during the build phase and uses `Source.no_source()` for simplicity. For deployment, ensure your AWS environment is configured (e.g., `aws configure`) and you have bootstrapped your CDK environment (`cdk bootstrap`). You can then run `cdk synth` to generate CloudFormation or `cdk deploy` to deploy it.

import os
from aws_cdk import (  # type: ignore
    core as cdk,
    aws_codebuild as codebuild
)

class MyCodeBuildStack(cdk.Stack):
    def __init__(self, scope: cdk.App, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        # Define a simple CodeBuild project that prints a message
        codebuild.Project(
            self,
            "MySimpleBuildProject",
            project_name="MySimpleBuildProject",
            build_spec=codebuild.BuildSpec.from_object({
                "version": "0.2",
                "phases": {
                    "install": {
                        "commands": [
                            "echo 'Installing dependencies...'"
                        ]
                    },
                    "build": {
                        "commands": [
                            "echo 'Hello from CodeBuild!'",
                            "env"
                        ]
                    }
                },
                "artifacts": {
                    "files": []
                }
            }),
            source=codebuild.Source.no_source(), # No external source needed for this basic example
            environment=codebuild.BuildEnvironment(
                build_image=codebuild.LinuxBuildImage.STANDARD_5_0
            )
        )

app = cdk.App()
MyCodeBuildStack(app, "CodeBuildQuickstartStack")
app.synth()

view raw JSON →