AWS Builder Center
Gatekeeper, Take Two: Moving the Reasoning to AgentCore Runtime Without Touching the Approval Gate

Gatekeeper, Take Two: Moving the Reasoning to AgentCore Runtime Without Touching the Approval Gate

Gatekeeper's reasoning now runs on Amazon Bedrock AgentCore Runtime, invoked by a thin Lambda with no Bedrock permissions. The approval gate hasn't moved.

Cloud Engineer

Vision & What Changed

A couple of weeks ago I built Gatekeeper: a Lambda that wakes up at 03:00 JST, checks twelve of my production apps, reads the AWS What's New feed, and drafts a morning digest with a Strands agent calling Bedrock directly. The one thing it's never allowed to do on its own is publish that digest — that goes through a DynamoDB approval queue and an email link, because publishing is the only action anyone outside my inbox would ever see.
That part hasn't changed. What changed is where the actual thinking happens. The night-run Lambda used to build a  strands.Agent , attach a  BedrockModel , and run the whole reasoning loop itself, in the same process that also had  dynamodb:PutItem  and  sns:Publish  permissions. It bothered me a little that the piece of code with the widest blast radius (an LLM following instructions from an RSS feed I don't control) was living right next to the pieces that touch my approval queue. So I pulled the reasoning out entirely and put it on Amazon Bedrock AgentCore Runtime. Lambda now does exactly one thing: call the runtime, get back a digest, and queue it.

How I Built It

The move itself is small on paper.  agent/agent.py  is basically the old  night_run/handler.py  with the Bedrock-calling half kept and the DynamoDB/SNS half deleted, wrapped in  bedrock_agentcore.runtime.BedrockAgentCoreApp :
app = BedrockAgentCoreApp()

@app.entrypoint
def invoke(payload: dict) -> dict:
run_date = payload.get("run_date", ...)
agent = build_agent()
digest_md = str(agent(TASK_PROMPT.format(run_date=run_date))).strip()
return {"digest_md": digest_md}
 agentcore configure --non-interactive  picked Direct Code Deploy instead of a container build, which I hadn't asked for but which turned out to be the right call — no Dockerfile, no ECR repo, no CodeBuild project, just a zip uploaded straight to the runtime. What's left in  night_run/handler.py  is a dozen lines that call  boto3.client("bedrock-agentcore").invoke_agent_runtime(...) , parse  digest_md  out of the response, and do exactly what it did before.
None of that went smoothly on the first try, though.
Attempt one failed with "Runtime initialization time exceeded. Please make sure that initialization completes in 30s." That sounds like a performance problem. It wasn't — I'd forgotten to pass  WATCHED_APPS  to the runtime with  agentcore deploy --env , so the module crashed on  os.environ["WATCHED_APPS"]  at import time, and the platform reported the crash as a timeout instead of the  KeyError  it actually was. Tailing CloudWatch Logs showed the real traceback in about ten seconds; the console-level error message on its own would have sent me looking in the wrong place.
Attempt two got past that and failed with  AccessDeniedException  on  bedrock-agentcore:InvokeAgentRuntime , even though the Lambda's IAM policy explicitly allowed that action on the runtime ARN. It turns out the actual resource being checked is the runtime's endpoint, one level deeper:  .../runtime/gatekeeper-s1ZqWD2EMM/runtime-endpoint/DEFAULT , not the bare runtime ARN. Adding a second Resource entry with  /runtime-endpoint/*  appended fixed it.
Attempt three got past IAM and failed with  ResourceNotFoundException: No endpoint or agent found with qualifier 'DEFAULT'  — for a runtime and endpoint that definitely existed, confirmed by  list-agent-runtime-endpoints  in the same terminal. The runtime lives in us-east-1; the night-run Lambda lives in ap-northeast-1 for latency to the apps it checks. My  boto3.client("bedrock-agentcore")  call had no explicit region, so it silently inherited the Lambda's own  AWS_REGION  and queried the wrong regional control plane for an ARN that, confusingly, contains the correct region as plain text. Pinning  region_name="us-east-1"  on that one client was the whole fix.
Three failures, three different layers (config, IAM, region), each with an error message that pointed slightly away from the real cause. That's the part worth writing down more than the migration itself.


AWS Services Used / Architecture Overview

EventBridge Scheduler still wakes  gatekeeper-night-run  on the same Asia/Tokyo cron. That Lambda now calls Amazon Bedrock AgentCore Runtime (us-east-1) via  InvokeAgentRuntime , gets a digest back, writes it to DynamoDB as  pending , and publishes the report through SNS exactly as before. The approval Lambda behind a Function URL is untouched. The only new resource is the AgentCore Runtime itself, deployed independently through the  agentcore  CLI rather than through the CloudFormation stack that owns everything else — a deliberate seam, since the two have very different deploy cadences.
Flow: Scheduler → Lambda (thin invoker) → AgentCore Runtime (Strands + Bedrock) → Lambda → DynamoDB + SNS → human clicks a link → approval Lambda → digest goes public.

What I Learned

The IAM policy on the night-run role got shorter after this change, not longer:  bedrock:InvokeModel*  on  Resource: "*"  is gone, replaced by  bedrock-agentcore:InvokeAgentRuntime  scoped to one runtime ARN. The Lambda that decides whether a digest becomes public can no longer talk to a foundation model at all. Whatever the agent does wrong — an odd summary, a missed status check — it still can't touch the publish flag, and now it literally can't touch Bedrock either. Separating "what reasons" from "what's allowed to happen" was already the design goal of Gatekeeper. Moving the reasoning to its own runtime just made that separation something IAM enforces between two services instead of something I have to trust one Lambda's code to respect internally.
The smaller lesson: every one of the three bugs above surfaced as an error message that described a different problem than the actual one. A timeout that was a crash. An access-denied that was the wrong resource shape. A not-found that was the wrong region.  aws logs tail  and  list-agent-runtime-endpoints  answered each one in under a minute — the fix was never the hard part, finding which layer to look at was.
First post-migration night's digest, approved the next morning like always: all twelve apps healthy, and Gatekeeper still doesn't know it isn't the one who decides that.

Link to App or Repo

Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article