Skip to content
v2.277.0

CodeBuildProjectProps Struct ​

Customize the CodeBuild Event Target.

Example ​

ts
import * as codebuild from 'aws-cdk-lib/aws-codebuild';
import * as codecommit from 'aws-cdk-lib/aws-codecommit';

const repo = new codecommit.Repository(this, 'MyRepo', {
  repositoryName: 'aws-cdk-codebuild-events',
});

const project = new codebuild.Project(this, 'MyProject', {
  source: codebuild.Source.codeCommit({ repository: repo }),
});

const deadLetterQueue = new sqs.Queue(this, 'DeadLetterQueue');

// trigger a build when a commit is pushed to the repo
const onCommitRule = repo.onCommit('OnCommit', {
  target: new targets.CodeBuildProject(project, {
    deadLetterQueue: deadLetterQueue,
  }),
  branches: ['master'],
});
python
import aws_cdk.aws_codebuild as codebuild
import aws_cdk.aws_codecommit as codecommit


repo = codecommit.Repository(self, "MyRepo",
    repository_name="aws-cdk-codebuild-events"
)

project = codebuild.Project(self, "MyProject",
    source=codebuild.Source.code_commit(repository=repo)
)

dead_letter_queue = sqs.Queue(self, "DeadLetterQueue")

# trigger a build when a commit is pushed to the repo
on_commit_rule = repo.on_commit("OnCommit",
    target=targets.CodeBuildProject(project,
        dead_letter_queue=dead_letter_queue
    ),
    branches=["master"]
)
java
import software.amazon.awscdk.services.codebuild.*;
import software.amazon.awscdk.services.codecommit.*;


Repository repo = Repository.Builder.create(this, "MyRepo")
        .repositoryName("aws-cdk-codebuild-events")
        .build();

Project project = Project.Builder.create(this, "MyProject")
        .source(Source.codeCommit(CodeCommitSourceProps.builder().repository(repo).build()))
        .build();

Queue deadLetterQueue = new Queue(this, "DeadLetterQueue");

// trigger a build when a commit is pushed to the repo
Rule onCommitRule = repo.onCommit("OnCommit", OnCommitOptions.builder()
        .target(CodeBuildProject.Builder.create(project)
                .deadLetterQueue(deadLetterQueue)
                .build())
        .branches(List.of("master"))
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
using Amazon.CDK.AWS.CodeBuild;
using Amazon.CDK.AWS.CodeCommit;


var repo = new Repository(this, "MyRepo", new RepositoryProps {
    RepositoryName = "aws-cdk-codebuild-events"
});

var project = new Project(this, "MyProject", new ProjectProps {
    Source = Source.CodeCommit(new CodeCommitSourceProps { Repository = repo })
});

var deadLetterQueue = new Queue(this, "DeadLetterQueue");

// trigger a build when a commit is pushed to the repo
var onCommitRule = repo.OnCommit("OnCommit", new OnCommitOptions {
    Target = new CodeBuildProject(project, new CodeBuildProjectProps {
        DeadLetterQueue = deadLetterQueue
    }),
    Branches = new [] { "master" }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
import "github.com/aws/aws-cdk-go/awscdk"
import codecommit "github.com/aws/aws-cdk-go/awscdk"


repo := codecommit.NewRepository(this, jsii.String("MyRepo"), &RepositoryProps{
	RepositoryName: jsii.String("aws-cdk-codebuild-events"),
})

project := codebuild.NewProject(this, jsii.String("MyProject"), &ProjectProps{
	Source: codebuild.Source_CodeCommit(&CodeCommitSourceProps{
		Repository: repo,
	}),
})

deadLetterQueue := sqs.NewQueue(this, jsii.String("DeadLetterQueue"))

// trigger a build when a commit is pushed to the repo
onCommitRule := repo.onCommit(jsii.String("OnCommit"), &OnCommitOptions{
	Target: targets.NewCodeBuildProject(project, &CodeBuildProjectProps{
		DeadLetterQueue: deadLetterQueue,
	}),
	Branches: []*string{
		jsii.String("master"),
	},
})

Properties ​

deadLetterQueueoptionalIQueuedead_letter_queueoptionalIQueuedeadLetterQueueoptionalIQueueDeadLetterQueueoptionalIQueueDeadLetterQueueoptionalIQueue #
The SQS queue to be used as deadLetterQueue. Check out the considerations for using a dead-letter queue.

Default: no dead-letter queue

notes

The events not successfully delivered are automatically retried for a specified period of time, depending on the retry policy of the target. If an event is not delivered before all retry attempts are exhausted, it will be sent to the dead letter queue.

eventoptionalRuleTargetInputeventoptionalRuleTargetInputeventoptionalRuleTargetInputEventoptionalRuleTargetInputEventoptionalRuleTargetInput #
The event to send to CodeBuild.

Default: the entire EventBridge event

This will be the payload for the StartBuild API.

eventRoleoptionalIRoleevent_roleoptionalIRoleeventRoleoptionalIRoleEventRoleoptionalIRoleEventRoleoptionalIRole #
The role to assume before invoking the target (i.e., the codebuild) when the given rule is triggered.

Default: a new role will be created

maxEventAgeoptionalDurationmax_event_ageoptionalDurationmaxEventAgeoptionalDurationMaxEventAgeoptionalDurationMaxEventAgeoptionalDuration = Duration.hours(24) #
The maximum age of a request that Lambda sends to a function for processing.

Minimum value of 60. Maximum value of 86400.

retryAttemptsoptionalnumberretry_attemptsoptionalint | floatretryAttemptsoptionalNumberRetryAttemptsoptionaldoubleRetryAttemptsoptional*float64 = 185 #
The maximum number of times to retry when the function returns an error.

Minimum value of 0. Maximum value of 185.