jonmatumalpha
conceptsnotesexperimentsessays

© 2026 Jonatan Mata · alpha · v0.1.0

Experiments

PR Auto-Approver

Serverless GitHub App that auto-approves pull requests after CI passes, with optional AI code review via Amazon Bedrock. Four repositories: Node.js/Probot app, AWS Terraform module (Lambda + API Gateway + Secrets Manager), GitHub Terraform module (webhooks), and deployment infra.

evergreen#github-app#probot#terraform#lambda#api-gateway#secrets-manager#bedrock#code-review#automation#ci-cd

What it is

A serverless GitHub App that auto-approves pull requests when all CI checks pass. Optionally, before approving, it sends the diff to Amazon Bedrock for an AI code review that detects bugs, security vulnerabilities, and performance issues.

The project is split into four repositories with clear responsibilities:

RepositoryVersionRole
pr-auto-approverv1.0.0Node.js/Probot app — business logic
terraform-aws-pr-auto-approverv1.2.0Terraform AWS module — Lambda, API Gateway, Secrets Manager
terraform-github-pr-auto-approverv1.0.0Terraform GitHub module — per-repo webhooks
pr-auto-approver-infralatestPrivate deployment — consumes the modules, branch protected

Architecture

Loading diagram...

Production demo

PR auto-approved by the bot after CI passes

The screenshot shows the full flow in the test repository: the owner comments on the Secrets Manager integration, the bot auto-approves with "All checks passed. Auto-approved by pr-auto-approver bot.", and the PR is merged — all in under a minute.

How it works

The full flow from PR creation to approval:

  1. A PR is opened or a check suite completes → GitHub sends a webhook
  2. API Gateway HTTP receives the POST and routes it to Lambda
  3. Lambda (Probot) validates the webhook HMAC signature using the secret from Secrets Manager
  4. Verifies the PR author is in the allowed authors list
  5. Waits for all check suites to complete successfully
  6. If Bedrock is enabled: sends the diff to the model for code review
  7. If the review finds no issues → approves the PR
  8. If issues are found → posts review comments and requests changes

Security

Secrets management follows the principle of least privilege:

  • The GitHub App private key and webhook secret are stored in AWS Secrets Manager
  • Lambda receives Secrets Manager ARNs as environment variables — raw values are never exposed
  • On cold start, Lambda reads the secrets and caches them in memory for subsequent invocations
  • The IAM role has secretsmanager:GetSecretValue permissions only for the specific ARNs
  • Bedrock permissions (bedrock:InvokeModel) are added only when bedrock_enabled = true

AWS module — resources created

The terraform-aws-pr-auto-approver v1.2.0 module creates:

ResourceConfiguration
LambdaNode.js 20, 128 MB / 30s (no Bedrock), 256 MB / 120s (with Bedrock)
API Gateway v2HTTP API with POST route
Secrets Manager2 secrets (private key + webhook secret)
IAM RoleLeast-privilege, conditional Bedrock
CloudWatch Logs14-day retention
CloudWatch DashboardLambda, API GW, Bedrock metrics (optional)
CloudWatch AlarmsErrors, throttles, high duration, 5xx
SNS TopicEmail alerts (optional)
AWS BudgetMonthly Bedrock budget (optional)

GitHub module — webhooks

The terraform-github-pr-auto-approver v1.0.0 module configures webhooks on each specified repository:

module "approver_github" {
  source  = "jonmatum/pr-auto-approver/github"
  version = "~> 1.0"
 
  webhook_url         = module.approver_infra.webhook_url
  webhook_secret      = var.webhook_secret
  github_repositories = ["repo-one", "repo-two"]
}

It subscribes each repository to pull_request and check_suite events, pointing to the API Gateway endpoint.

Bedrock AI code review

Bot requesting changes after finding vulnerabilities in the code

When bedrock_enabled = true, Lambda sends the PR diff to Claude 3 Haiku (configurable) before approving. In the screenshot, the bot detected 3 issues in intentionally vulnerable code — including a SQL injection from directly concatenating req.query.id — and requested changes instead of approving. The model reviews for:

  • Bugs and logic errors
  • Security vulnerabilities
  • Performance issues
  • Missing error handling

If Bedrock is disabled or fails, the bot falls back to auto-approve after CI passes — the AI review never blocks the flow.

Why it matters

In teams with AI agents that generate PRs automatically — like the content agent in this knowledge base — the bottleneck shifts from "writing code" to "reviewing and approving PRs." This bot eliminates the manual wait for PRs from trusted authors that already passed CI, while the optional Bedrock layer adds a code review safety net without human intervention.

References

  • GitHub Apps documentation — GitHub, 2024. Official documentation for creating GitHub Apps with granular permissions.
  • Probot framework — GitHub, 2024. Framework for building GitHub Apps with Node.js.
  • AWS Secrets Manager — AWS, 2024. Service for managing secrets with automatic rotation.
  • Amazon API Gateway HTTP APIs — AWS, 2024. Low-latency, low-cost HTTP APIs.
  • Amazon Bedrock — AWS, 2024. Managed service for accessing foundation models.

Related content

  • GitHub Actions

    GitHub's native CI/CD platform. Declarative YAML workflows that automate build, test, deploy, and any development lifecycle task — directly from the repository.

  • Terraform

    HashiCorp's Infrastructure as Code tool that enables defining, provisioning, and managing multi-cloud infrastructure through declarative HCL files.

  • AWS Lambda

    AWS serverless compute service that runs code in response to events without provisioning or managing servers, automatically scaling from zero to thousands of concurrent executions.

  • AWS API Gateway

    AWS managed service for creating, publishing, and managing REST, HTTP, and WebSocket APIs that act as entry points to Lambda functions and other backend services.

  • Secrets Management

    Practices and tools for securely storing, distributing, and rotating credentials, API keys, and other sensitive data in applications and pipelines.

  • Serverless

    Cloud computing model where the provider manages infrastructure automatically, allowing code execution without provisioning or managing servers, paying only for actual usage.

  • Infrastructure as Code

    Practice of defining and managing infrastructure through versioned configuration files instead of manual processes. Foundation of modern operations automation.

  • CI/CD

    Continuous Integration and Continuous Delivery/Deployment — practices that automate code integration, testing, and delivery to production. Foundation of modern software engineering.

Experiments