Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 393
programing_is_hard Avatar asked May 09 '19 21:05

programing_is_hard


People also ask

How does the AWS CodePipeline webhook work?

The AWS::CodePipeline::Webhook resource creates and registers your webhook. After the webhook is created and registered, it triggers your pipeline to start every time an external event occurs. For more information, see Configure Your GitHub Pipelines to Use Webhooks for Change Detection in the AWS CodePipeline User Guide .

Does CloudFormation create webhooks when creating your own repository?

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. Codepipeline UI. Organization Github Repo. It asked to login the github. Logged in with my admin credential => successfully created webhook and services.

What happens after a webhook is created and registered?

After the webhook is created and registered, it triggers your pipeline to start every time an external event occurs. For more information, see Configure Your GitHub Pipelines to Use Webhooks for Change Detection in the AWS CodePipeline User Guide . We strongly recommend that you use AWS Secrets Manager to store your credentials.

How do I use AWS CloudFormation templates to filter webhook events?

To use an AWS CloudFormation template to filter webhook events, use the AWS CodeBuild project's FilterGroups property. The following YAML-formatted portion of an AWS CloudFormation template creates two filter groups. Together, they trigger a build when one or both evaluate to true:


Video Answer


1 Answers

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

like image 131
Greeshma Avatar answered Oct 21 '22 22:10

Greeshma