Search code examples
amazon-web-servicesaws-codepipelinegithub-webhook

AWS Codepipeline Github Webhook not being registered through cloudformation


I am trying to set AWS codepipeline and use github as the source by using cloudformation. The github repository is owned by an organization and I have admin access to it.

I was able to create webhook and successfully create entire service through codepipeline UI. But when I am trying to do same thing through Cloudformation Document, it returns error

Webhook could not be registered with GitHub. Error cause: Not found [StatusCode: 404, Body: {"message":"Not Found","documentation_url":"https://developer.github.com/v3/repos/hooks/#create-a-hook"}]

I used same credential both times (OAuth token in cloudformation and actual login popups in codepipeline UI), but when I do it through Cloudformation it failed.

I suspected my cloudformation document was the issue. But when I create my own repository, cloudformation successfully create webhook and created full codepipeline service.

Below is the summary of tests I did to understand where it went wrong.

  1. Codepipeline UI. Organization Github Repo. It asked to login the github. Logged in with my admin credential => successfully created webhook and services.
  2. Cloudformation. Organization Github Repo. Used OAuth Token from admin credential with repo and admin:repo_hook enabled. => Gave out error above
  3. Cloudformation. Personal Github Repo. Used Oauth Token from admin credential with repo and admin:repo_hook enabled => successfully created webhook and services

The following is portion of cloudformation document where I create Webhook.

  AppPipelineWebhook:
    Type: 'AWS::CodePipeline::Webhook'
    Properties:
      Authentication: GITHUB_HMAC
      AuthenticationConfiguration:
        SecretToken: !Ref GitHubSecret
      Filters:
        - JsonPath: $.ref
          MatchEquals: 'refs/heads/{Branch}'
      TargetPipeline: !Ref cfSSMAutomationDev
      TargetAction: SourceAction
      Name: AppPipelineWebhook
      TargetPipelineVersion: !GetAtt cfSSMAutomationDev.Version
      RegisterWithThirdParty: true

So I am not sure what is wrong. My suspicion is that OAuth token requires more privilege. Does anyone have similar experience with this? Any suggestion is much appreciated


Solution

  • Even I was facing the same issue, by seeing codepipeline UI configuration's Repository I used

    {
      "Configuration": {
        "Owner": "myUserName",
        "Repo": "orgname/repository-name",
      }
    }
    

    so cloudformation was checking for the repository myUserName/orgname/repository-name which wasn't exist.

    It got solved after following the below solution:

    {
      "Configuration": {
        "Owner": "orgname",
        "Repo": "repository-name",
      }
    }
    

    private repo -> ownerName: YourUserName
    organisation repo -> ownerName: OrganisationName