Each time I needed to react to a webhook on AWS, I built the same small stack: an API Gateway endpoint, a Lambda function to check the signature, and a PutEvents call to push the payload to an event bus. It isn't much code, but it's still code I have to deploy and maintain.
Last Friday, AWS announced Webhook Events for the EventBridge Custom event bus. You create a webhook event source on a bus and EventBridge gives you an HTTPS URL. It checks each request with an HMAC signature, a static token or basic authentication, and publishes the accepted ones to the bus. I find it one of the most interesting launches of this first week of pre:Invent, because that whole stack becomes configuration.
In this post I walk you through the setup I now use on my repositories. Each time a pull request is opened or updated, a Kiro CLI session starts on my machine and reviews it. In a second post, the same webhook calls an Amazon Bedrock AgentCore agent that comments on the PR.
All the files are in this repo.
Setting up webhook events on Eventbridge
Here's what this post helps you build:
GitHub (X-Hub-Signature-256) -> EventBridge webhook event source -> Custom event bus -> subscriber: filter on pull_request opened/synchronize/reopened, JSONata transform -> SQS queue (+ DLQ) -> poll-sqs-kiro.sh on my machine -> one detached kiro-cli session per PR event Kiro CLI runs on my laptop, so it pulls work from an SQS queue rather than exposing an endpoint. The queue also gives me retries and a dead-letter queue.
Let's go step by step:
Prerequisites
- AWS CLI 2.42.1 or later (this feature relies on the enhanced Custom event bus which has its own namespace,
aws eventsv2, and theaws eventscommands only manage classic buses. - Tooling like
jq,openssl,curl,envsubstandgh. - Kiro CLI
export AWS_REGION=us-east-1 export ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text) Step 1: create an event bus
export BUS_ARN=$(aws eventsv2 create-event-bus --name kiro-gh-bus \ --query EventBusArn --output text) aws eventsv2 describe-event-bus --event-bus-arn "$BUS_ARN" --query State The bus is ACTIVE after about ten seconds. Buses, sources and subscribers are all addressed by ARN.
Step 2: create the webhook source
The source assumes an IAM role for two things.
- it publishes to the bus with
events:PutWebhookEvents, - it reads the signing secret with
secretsmanager:GetSecretValue. The second permission matters: if the role can't read the secret, EventBridge can't check signatures and answers 403 to every request.
Save the following json to iam/webhook-source-policy.json
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "events:PutWebhookEvents", "Resource": "${BUS_ARN}" }, { "Effect": "Allow", "Action": "secretsmanager:GetSecretValue", "Resource": "arn:aws:secretsmanager:${AWS_REGION}:${ACCOUNT_ID}:secret:events-webhook!*" } ] } then create the role
aws iam create-role --role-name kiro-gh-webhook-source \ --assume-role-policy-document "$(envsubst < iam/trust-policy.json)" aws iam put-role-policy --role-name kiro-gh-webhook-source --policy-name webhook \ --policy-document "$(envsubst < iam/webhook-source-policy.json)" GitHub signs each delivery with an HMAC-SHA256 of the raw body, sent in X-Hub-Signature-256 with a sha256= prefix. That maps directly to the source's HMAC settings, in WebhookEventsConfiguration:
aws eventsv2 create-event-source --name github --event-bus-arn "$BUS_ARN" \ --configuration "{\"WebhookEventsConfiguration\":{ \"RoleArn\":\"arn:aws:iam::${ACCOUNT_ID}:role/kiro-gh-webhook-source\", \"AuthConfiguration\":{\"HmacAuthConfiguration\":{ \"Algorithm\":\"SHA256\",\"Encoding\":\"HEX\", \"SignatureHttpHeader\":\"X-Hub-Signature-256\",\"SignaturePrefix\":\"sha256=\", \"SignedMessageComposition\":\"BODY\"}}, \"MetadataHttpHeaders\":[\"x-github-event\",\"x-github-delivery\"]}}" > source.json export WEBHOOK_URL=$(jq -r .EventSourceDetails.WebhookDetails.WebhookUrl source.json) export WEBHOOK_SECRET=$(aws secretsmanager get-secret-value \ --secret-id "$(jq -r .EventSourceDetails.WebhookDetails.SecretArn source.json)" \ --query SecretString --output text) EventBridge generates the secret and stores it in Secrets Manager. Keep the URL private too: anyone who has both can publish to your bus.
The request body arrives unchanged in the event's Data. The headers listed in MetadataHttpHeaders are copied into Metadata. GitHub sends the event type in the X-GitHub-Event header and not in the body, so this is how the subscriber tells a pull_request from an issues event.
Step 3: create the queues
export DLQ_ARN=arn:aws:sqs:${AWS_REGION}:${ACCOUNT_ID}:kiro-gh-dlq aws sqs create-queue --queue-name kiro-gh-dlq export QUEUE_URL=$(aws sqs create-queue --queue-name kiro-gh-tasks --attributes "{ \"ReceiveMessageWaitTimeSeconds\":\"20\", \"RedrivePolicy\":\"{\\\"deadLetterTargetArn\\\":\\\"$DLQ_ARN\\\",\\\"maxReceiveCount\\\":\\\"3\\\"}\" }" --query QueueUrl --output text) export QUEUE_ARN=arn:aws:sqs:${AWS_REGION}:${ACCOUNT_ID}:kiro-gh-tasks The subscriber delivers with its own role, which has sqs:SendMessage on both queues. The queue doesn't need a resource policy.
aws iam create-role --role-name kiro-gh-subscriber \ --assume-role-policy-document "$(envsubst < iam/trust-policy.json)" aws iam put-role-policy --role-name kiro-gh-subscriber --policy-name send-sqs \ --policy-document "$(envsubst < iam/subscriber-policy.json)" Step 4: filter and transform
A subscriber accepts one filter per scope, and an event must match all of them. The GitHub event type is in METADATA and the action is in the body, so in DATA:
{ "Filters": [ { "Scope": "METADATA", "Pattern": "{\"x-github-event\":[\"pull_request\"]}" }, { "Scope": "DATA", "Pattern": "{\"action\":[\"opened\",\"synchronize\",\"reopened\"]}" } ] } Transformers on the new bus use JSONata. JSONata builds the JSON object itself, so a quote or a newline in a GitHub field can't break the message. The event is available as $events:
{% { "repo": $events.Data.repository.full_name, "number": $events.Data.number, "url": $events.Data.pull_request.html_url, "author": $events.Data.pull_request.user.login, "action": $events.Data.action, "delivery": $events.Metadata.`x-github-delivery`, "prompt": "Review pull request " & $string($events.Data.number) & " in " & $events.Data.repository.full_name & " ..." } %} The expression must be wrapped in {% %}, with nothing after %}, not even a final newline. I strip it when I build the transformer:
jq -n --rawfile e transformer.jsonata \ '{Type:"JSONATA",JsonataConfiguration:{Expression:($e|rtrimstr("\n"))}}' > /tmp/transformer.json aws eventsv2 create-subscriber --name github-pr-to-kiro --event-bus-arn "$BUS_ARN" \ --type UNORDERED \ --invoke-configuration "{\"RoleArn\":\"arn:aws:iam::${ACCOUNT_ID}:role/kiro-gh-subscriber\",\"TargetArn\":\"$QUEUE_ARN\"}" \ --filter-configuration file://filter-configuration.json \ --transformer file:///tmp/transformer.json \ --on-failure-configuration "{\"Arn\":\"$DLQ_ARN\"}" I leave the PR title and description out of the prompt. They are free text written by whoever opened the PR, which makes them the easiest place to hide a prompt injection.
Step 5: add the webhook to your GitHub repo
Now GitHub needs to know where to send its events. On the repository, go to Settings > Webhooks > Add webhook and fill in:
- Payload URL: the
WEBHOOK_URLfrom step 2; - Content type:
application/json; - Secret: the
WEBHOOK_SECRETfrom step 2; - Which events: choose "Let me select individual events" and tick only Pull requests.
If you prefer the command line, the GitHub CLI does the same thing:
jq -n '{name:"web", active:true, events:["pull_request"], config:{url:env.WEBHOOK_URL, content_type:"json", secret:env.WEBHOOK_SECRET}}' | gh api "repos/OWNER/REPO/hooks" --method POST --input - jq builds the webhook definition from your two environment variables, and gh api sends it to GitHub's "create a repository webhook" endpoint. Passing it on stdin keeps the secret out of your shell history and out of ps.
As soon as the webhook exists, GitHub sends it a ping event. You'll see it under Recent Deliveries on the webhook page, with a 200 response from EventBridge. The filter drops it, since it isn't a pull_request event, so nothing reaches the queue.
Step 6: test
You can test without GitHub by signing a request yourself:
BODY='{"action":"opened","number":7,"repository":{"full_name":"OWNER/REPO"},"pull_request":{"html_url":"https://github.com/OWNER/REPO/pull/7","user":{"login":"octocat"}}}' SIG="sha256=$(printf '%s' "$BODY" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET" -hex | awk '{print $NF}')" curl -s -w ' %{http_code}\n' -X POST "$WEBHOOK_URL" \ -H 'Content-Type: application/json' -H 'X-GitHub-Event: pull_request' \ -H "X-Hub-Signature-256: $SIG" --data-binary "$BODY" aws sqs receive-message --queue-url "$QUEUE_URL" --wait-time-seconds 10 --visibility-timeout 0 A valid signature returns 200 and the message shows up in the queue, with the prompt field. A wrong or missing signature returns 403. A closed action or an issues event is accepted by the source and dropped by the filter.
Step 7: run Kiro
poll-sqs-kiro.sh long polls the queue and handles one message at a time. For each message, it:
- starts
kiro-cli chat --v3 --no-interactive --output-format stream-jsonwithnohup, in the background, in your checkout; - waits for the session ID, which appears in the first
stream-jsonevents after a few seconds; - deletes the message and adds a line to
kiro-runs/runs.tsvwith the session ID, the PID andrepo#number action.
If no session ID appears within a minute, the script kills the process and leaves the message on the queue. After three attempts, SQS moves it to the DLQ. The review itself has no time limit.
export QUEUE_URL export WORKDIR=$HOME/src/my-repo ./poll-sqs-kiro.sh By default the script trusts read and grep_search, so Kiro can read, list and search files, and nothing else. read is the whole read capability. With only read_file, Kiro can't list the directory. The script doesn't check out the PR branch, so Kiro sees the checkout as it is. If you add a gh pr checkout step, keep in mind that Kiro then reads code written by the PR author.
Step 8: pick up a review
Each run writes its events to kiro-runs/<messageId>.jsonl, and tail -f on that file shows progress. When the last line is runFinished, you can open the session interactively and keep working with it:
cd ~/src/my-repo # sessions are stored per directory kiro-cli chat --v3 --resume-id sess_964e8292-... A session can't be resumed while its headless run is still going. Kiro answers SessionHeldElsewhereError, because the background process owns the session until it ends.
Cost
For a personal repo, the only line you'll notice on the AWS bill is the webhook secret: Secrets Manager charges $0.40 per secret per month. Everything else is measured in fractions of a cent. The enhanced Custom event bus charges by data volume, $0.18 per GB in and $0.05 per GB out, and Webhook Events have no extra fee. A pull_request payload is a few tens of KB, so a hundred PR events a month is a few MB. The JSONata transform counts as an event evaluation at $0.15 per million events, one day of storage on the bus is included, and SQS stays inside its free tier.
The real cost is Kiro: each review uses Kiro credits.
Next
I use SQS and a poller here because Kiro runs on my own machine. If your agent runs in AWS, a subscriber can call it directly. I'll cover this in a follow-up post!
