TL;DR
We’ll create a workflow where every pull request triggers a GitHub Action that:
-
extracts the PR diff
-
sends it to AWS Bedrock for analysis
-
posts the review back as a PR comment
Follow along here:
Architecture
Pull Request → GitHub Actions → PR Diff → Bedrock InvokeModel → Review Output → PR Comment
Prerequisites
-
Terraform installed
-
AWS credentials configured locally (or via CI)
-
A GitHub repo to host the workflow + script
-
A Bedrock model enabled in your AWS account/region
-
Copilot or another LLM
Step 1 — Create your project structure
Structure:
-
infra/(Terraform for AWS resources) -
scripts/(Python code that calls Bedrock + comments on PR) -
.github/workflows/(GitHub Actions workflow)
Step 2 — Provision baseline Terraform infrastructure
In infra/, define the following utilizing copilot:
-
S3 bucket for Terraform remote state
-
encryption enabled
-
versioning enabled
-
public access blocked
-
-
DynamoDB table for state locking
This gives you the “real world” Terraform baseline (especially if you expand this project later).
Step 3 — Configure GitHub OIDC → AWS IAM Role (Terraform)
Create:
-
OpenID Connect Provider for GitHub Actions
-
IAM Role that can be assumed via
sts:AssumeRoleWithWebIdentity -
Restrict the trust policy to your repo (ex:
repo:OWNER/REPO:*) -
Attach the minimum permissions your workflow needs, such as:
-
bedrock:InvokeModel -
logs:CreateLogGroup -
logs:CreateLogStream(and typically log write permissions if you add them)
-
This avoids storing long-lived AWS keys in GitHub secrets.
Step 4 — Add the GitHub Actions workflow
Create .github/workflows/ai-pr-review.yml that triggers on pull_request and includes:
-
checkout the repository
-
configure AWS credentials (OIDC assume role)
-
extract the PR diff
-
run your Python reviewer script
-
post the output as a PR comment
Required workflow permissions typically include:
-
id-token: write -
contents: read -
pull-requests: write
Add a GitHub secret for your AWS role ARN (ex: AWS_ROLE_ARN) and reference it in the workflow.
Step 5 — Write the Python Bedrock reviewer script
Your script should:
-
Read the diff text (limit size so you don’t exceed model input)
-
Build a structured “DevOps PR Review” prompt (security, performance, best practices)
-
Call Bedrock via
boto3invoke_model -
Parse the response
-
Post the response back to the PR using GitHub’s API
Keep the output readable:
-
start with a short summary
-
list risks + recommendations in bullets
-
include “actionable next steps”
Step 6 — Test end-to-end
-
Create a branch
-
Make a small change (README edit)
-
Open a pull request
-
Confirm the workflow runs and posts a comment
Then test a “security scenario”:
-
add intentionally risky Terraform (ex: open ingress / missing SG / hardcoded AMI)
-
open another PR
-
verify the AI calls out the issues
Next ideas (optional)
-
Add Terraform
fmt/validate/plansteps in CI -
Add policy-as-code checks (OPA/Conftest)
-
Store review output as an artifact
-
Add “severity scoring” in the prompt
