java.lang.Object
software.amazon.jsii.JsiiObject
All Implemented Interfaces:
IAction, software.amazon.jsii.JsiiSerializable

@Generated(value="jsii-pacmak/1.104.0 (build e79254c)", date="2024-11-22T02:23:58.959Z") @Stability(Stable) public class CodeBuildAction extends Action
CodePipeline build action that uses AWS CodeBuild.

Example:

 // Create a Cloudfront Web Distribution
 import software.amazon.awscdk.services.cloudfront.*;
 Distribution distribution;
 // Create the build project that will invalidate the cache
 PipelineProject invalidateBuildProject = PipelineProject.Builder.create(this, "InvalidateProject")
         .buildSpec(BuildSpec.fromObject(Map.of(
                 "version", "0.2",
                 "phases", Map.of(
                         "build", Map.of(
                                 "commands", List.of("aws cloudfront create-invalidation --distribution-id ${CLOUDFRONT_ID} --paths \"/*\""))))))
         .environmentVariables(Map.of(
                 "CLOUDFRONT_ID", BuildEnvironmentVariable.builder().value(distribution.getDistributionId()).build()))
         .build();
 // Add Cloudfront invalidation permissions to the project
 String distributionArn = String.format("arn:aws:cloudfront::%s:distribution/%s", this.account, distribution.getDistributionId());
 invalidateBuildProject.addToRolePolicy(PolicyStatement.Builder.create()
         .resources(List.of(distributionArn))
         .actions(List.of("cloudfront:CreateInvalidation"))
         .build());
 // Create the pipeline (here only the S3 deploy and Invalidate cache build)
 Bucket deployBucket = new Bucket(this, "DeployBucket");
 Artifact deployInput = new Artifact();
 Pipeline.Builder.create(this, "Pipeline")
         .stages(List.of(StageProps.builder()
                 .stageName("Deploy")
                 .actions(List.of(
                     S3DeployAction.Builder.create()
                             .actionName("S3Deploy")
                             .bucket(deployBucket)
                             .input(deployInput)
                             .runOrder(1)
                             .build(),
                     CodeBuildAction.Builder.create()
                             .actionName("InvalidateCache")
                             .project(invalidateBuildProject)
                             .input(deployInput)
                             .runOrder(2)
                             .build()))
                 .build()))
         .build();
 
  • Constructor Details

    • CodeBuildAction

      protected CodeBuildAction(software.amazon.jsii.JsiiObjectRef objRef)
    • CodeBuildAction

      protected CodeBuildAction(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • CodeBuildAction

      @Stability(Stable) public CodeBuildAction(@NotNull CodeBuildActionProps props)
      Parameters:
      props - This parameter is required.
  • Method Details

    • bound

      @Stability(Stable) @NotNull protected ActionConfig bound(@NotNull software.constructs.Construct scope, @NotNull IStage _stage, @NotNull ActionBindOptions options)
      This is a renamed version of the IAction.bind method.

      Specified by:
      bound in class Action
      Parameters:
      scope - This parameter is required.
      _stage - This parameter is required.
      options - This parameter is required.
    • variable

      @Stability(Stable) @NotNull public String variable(@NotNull String variableName)
      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.

      Parameters:
      variableName - the name of the variable to reference. This parameter is required.
      See Also: