BuildEnvironmentVariable

class aws_cdk.aws_codebuild.BuildEnvironmentVariable(*, type=None, value)

Bases: object

Parameters
  • type (Optional[BuildEnvironmentVariableType]) – The type of environment variable. Default: PlainText

  • value (Any) – The value of the environment variable. For plain-text variables (the default), this is the literal value of variable. For SSM parameter variables, pass the name of the parameter here (parameterName property of IParameter). For SecretsManager variables secrets, pass either the secret name (secretName property of ISecret) or the secret ARN (secretArn property of ISecret) here, along with optional SecretsManager qualifiers separated by ‘:’, like the JSON key, or the version or stage (see https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec.env.secrets-manager for details).

Example:

# Create a Cloudfront Web Distribution
import aws_cdk.aws_cloudfront as cloudfront
# distribution is of type Distribution


# Create the build project that will invalidate the cache
invalidate_build_project = codebuild.PipelineProject(self, "InvalidateProject",
    build_spec=codebuild.BuildSpec.from_object({
        "version": "0.2",
        "phases": {
            "build": {
                "commands": ["aws cloudfront create-invalidation --distribution-id ${CLOUDFRONT_ID} --paths "/*""
                ]
            }
        }
    }),
    environment_variables={
        "CLOUDFRONT_ID": codebuild.BuildEnvironmentVariable(value=distribution.distribution_id)
    }
)

# Add Cloudfront invalidation permissions to the project
distribution_arn = f"arn:aws:cloudfront::{this.account}:distribution/{distribution.distributionId}"
invalidate_build_project.add_to_role_policy(iam.PolicyStatement(
    resources=[distribution_arn],
    actions=["cloudfront:CreateInvalidation"
    ]
))

# Create the pipeline (here only the S3 deploy and Invalidate cache build)
deploy_bucket = s3.Bucket(self, "DeployBucket")
deploy_input = codepipeline.Artifact()
codepipeline.Pipeline(self, "Pipeline",
    stages=[codepipeline.StageProps(
        stage_name="Deploy",
        actions=[
            codepipeline_actions.S3DeployAction(
                action_name="S3Deploy",
                bucket=deploy_bucket,
                input=deploy_input,
                run_order=1
            ),
            codepipeline_actions.CodeBuildAction(
                action_name="InvalidateCache",
                project=invalidate_build_project,
                input=deploy_input,
                run_order=2
            )
        ]
    )
    ]
)

Attributes

type

The type of environment variable.

Default

PlainText

Return type

Optional[BuildEnvironmentVariableType]

value

The value of the environment variable.

For plain-text variables (the default), this is the literal value of variable. For SSM parameter variables, pass the name of the parameter here (parameterName property of IParameter). For SecretsManager variables secrets, pass either the secret name (secretName property of ISecret) or the secret ARN (secretArn property of ISecret) here, along with optional SecretsManager qualifiers separated by ‘:’, like the JSON key, or the version or stage (see https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec.env.secrets-manager for details).

Return type

Any