raulgomis / sam-github-webhook-handler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sam-github-webhook-handler

alt text

This is a production ready github webhook handler built and deployed using AWS SAM.

API-GW -> Lambda combination gives us an API capable of handling any POST requests sent by the Github Webhook. This Lambda function in-turn publishes to an SNS Topic and the idea is to subscribe any action listener on this topic. I am subscribing a sample Lambda event-processor for reference.

Why is SNS used in this architecture?

SNS is used to decouple the github-handler Lambda function from the event-processor. This lets the github-handler Lambda function respond to the webhook without waiting on the event-processor's response.

Use-cases:

  • Trigger a CI/CD Pipeline on git push/pull_request
  • Run unit tests/integration tests
  • Run static code analysis/Linting
  • Trigger workflows within AWS Cloud/on-premises

Pre-requisites:

Steps to run and deploy:

  • Clone the repository
git clone https://github.com/soumoks/sam-github-webhook-handler.git
  • Build the application
sam build -t sam_template.yaml
  • Test locally
sam local invoke GithubHandlerFunction
  • Package the application
sam package --template-file sam_template.yaml --output-template-file packaged.yaml --s3-bucket <s3_bucket_name>
  • Deploy
sam deploy --template-file packaged.yaml --stack-name github-handler-api --capabilities CAPABILITY_NAMED_IAM --region us-east-1

The above command returns an API endpoint that can be configured as a github webhook. Configure accordingly.

alt text

For additional information on github webhooks, please refer to the official documentation.

About


Languages

Language:Python 100.0%