Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CodeBuild Webhook in aws-cdk

What is the best way to create an AWS CodeBuild Project with a GitHub Webhook for running checks on Pull Requests using the aws-cdk?

like image 889
Assem Hasna Avatar asked Oct 26 '25 07:10

Assem Hasna


1 Answers

Unfortunately, as of writing this (December 2018), this functionality is not supported through CloudFormation (see AWS forum post here).

Because the CDK uses CloudFormation behind the scenes to perform deployments, if something is not supported in CloudFormation, we also can't support it in the CDK.

EDIT: I was actually wrong. While the branchFilter attribute that you see in the AWS Console for CodeBuild is not supported in CloudFormation, the webhook itself is.

Example code of creating a webhook with the CDK (in TypeScript):

import codebuild = require('@aws-cdk/aws-codebuild');
import cdk = require('@aws-cdk/cdk');

const project = new codebuild.Project(this, 'MyProject', {
  source: new codebuild.GitHubSource({
    owner: 'awslabs',
    repo: 'aws-cdk',
    oauthToken: new cdk.SecretParameter(this, 'GitHubOAuthToken', {
      ssmParameter: 'my-github-token',
    }),
    webhook: true, // default: false
  }),
  // remaining Project parameters here...
});

Note that you need CDK version 0.21.0 or later for this functionality to be present.

like image 175
Adam Ruka Avatar answered Oct 28 '25 20:10

Adam Ruka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!