class aws_cdk.aws_codepipeline_actions.CodeBuildAction(*, input, project, check_secrets_in_plain_text_env_variables=None, combine_batch_build_artifacts=None, environment_variables=None, execute_batch_build=None, extra_inputs=None, outputs=None, type=None, role=None, action_name, run_order=None, variables_namespace=None)

Bases: Action

CodePipeline build action that uses AWS CodeBuild.




# Create a Cloudfront Web Distribution
import aws_cdk.aws_cloudfront as cloudfront
# distribution: cloudfront.Distribution

# Create the build project that will invalidate the cache
invalidate_build_project = codebuild.PipelineProject(self, "InvalidateProject",
        "version": "0.2",
        "phases": {
            "build": {
                "commands": ["aws cloudfront create-invalidation --distribution-id ${CLOUDFRONT_ID} --paths "/*""
        "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}"

# 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",
  • input (Artifact) – The source to use as input for this action.

  • project (IProject) – The action’s Project.

  • check_secrets_in_plain_text_env_variables (Optional[bool]) – Whether to check for the presence of any secrets in the environment variables of the default type, BuildEnvironmentVariableType.PLAINTEXT. Since using a secret for the value of that kind of variable would result in it being displayed in plain text in the AWS Console, the construct will throw an exception if it detects a secret was passed there. Pass this property as false if you want to skip this validation, and keep using a secret in a plain text environment variable. Default: true

  • combine_batch_build_artifacts (Optional[bool]) – Combine the build artifacts for a batch builds. Enabling this will combine the build artifacts into the same location for batch builds. If executeBatchBuild is not set to true, this property is ignored. Default: false

  • environment_variables (Optional[Mapping[str, Union[BuildEnvironmentVariable, Dict[str, Any]]]]) – The environment variables to pass to the CodeBuild project when this action executes. If a variable with the same name was set both on the project level, and here, this value will take precedence. Default: - No additional environment variables are specified.

  • execute_batch_build (Optional[bool]) – Trigger a batch build. Enabling this will enable batch builds on the CodeBuild project. Default: false

  • extra_inputs (Optional[Sequence[Artifact]]) – The list of additional input Artifacts for this action. The directories the additional inputs will be available at are available during the project’s build in the CODEBUILD_SRC_DIR_ environment variables. The project’s build always starts in the directory with the primary input artifact checked out, the one pointed to by the input property. For more information, see .

  • outputs (Optional[Sequence[Artifact]]) – The list of output Artifacts for this action. Note: if you specify more than one output Artifact here, you cannot use the primary ‘artifacts’ section of the buildspec; you have to use the ‘secondary-artifacts’ section instead. See for details. Default: the action will not have any outputs

  • type (Optional[CodeBuildActionType]) – The type of the action that determines its CodePipeline Category - Build, or Test. Default: CodeBuildActionType.BUILD

  • role (Optional[IRole]) – The Role in which context’s this Action will be executing in. The Pipeline’s Role will assume this Role (the required permissions for that will be granted automatically) right before executing this Action. This Action will be passed into your IAction.bind method in the ActionBindOptions.role property. Default: a new Role will be generated

  • action_name (str) – The physical, human-readable name of the Action. Note that Action names must be unique within a single Stage.

  • run_order (Union[int, float, None]) – The runOrder property for this Action. RunOrder determines the relative order in which multiple Actions in the same Stage execute. Default: 1

  • variables_namespace (Optional[str]) – The name of the namespace to use for variables emitted by this action. Default: - a name will be generated, based on the stage and action names, if any of the action’s variables were referenced - otherwise, no namespace will be set


bind(scope, stage, *, bucket, role)

The callback invoked when this Action is added to a Pipeline.

Return type:


on_state_change(name, target=None, *, enabled=None, event_bus=None, schedule=None, targets=None, cross_stack_scope=None, description=None, event_pattern=None, rule_name=None)

Creates an Event that will be triggered whenever the state of this Action changes.

  • name (str) –

  • target (Optional[IRuleTarget]) –

  • enabled (Optional[bool]) – Indicates whether the rule is enabled. Default: true

  • event_bus (Optional[IEventBus]) – The event bus to associate with this rule. Default: - The default event bus.

  • schedule (Optional[Schedule]) – The schedule or rate (frequency) that determines when EventBridge runs the rule. You must specify this property, the eventPattern property, or both. For more information, see Schedule Expression Syntax for Rules in the Amazon EventBridge User Guide. Default: - None.

  • targets (Optional[Sequence[IRuleTarget]]) – Targets to invoke when this rule matches an event. Input will be the full matched event. If you wish to specify custom target input, use addTarget(target[, inputOptions]). Default: - No targets.

  • cross_stack_scope (Optional[Construct]) – The scope to use if the source of the rule and its target are in different Stacks (but in the same account & region). This helps dealing with cycles that often arise in these situations. Default: - none (the main scope will be used, even for cross-stack Events)

  • description (Optional[str]) – A description of the rule’s purpose. Default: - No description

  • event_pattern (Union[EventPattern, Dict[str, Any], None]) – Additional restrictions for the event to route to the specified target. The method that generates the rule probably imposes some type of event filtering. The filtering implied by what you pass here is added on top of that filtering. Default: - No additional filtering based on an event pattern.

  • rule_name (Optional[str]) – A name for the rule. Default: AWS CloudFormation generates a unique physical ID.

Return type:



Reference a CodePipeline variable defined by the CodeBuild project this action points to.

Variables in CodeBuild actions are defined using the ‘exported-variables’ subsection of the ‘env’ section of the buildspec.


variable_name (str) – the name of the variable to reference. A variable by this name must be present in the ‘exported-variables’ section of the buildspec


Return type:




The simple properties of the Action, like its Owner, name, etc.

Note that this accessor will be called before the bind callback.