
Weekend Productivity Challenge: PolicyLens
A serverless IAM policy reviewer that turns dense policy JSON into ranked, plain-English security findings and a rewritten least-privilege policy. A deterministic rule engine runs first so every finding is verifiable, with Amazon Bedrock and Nova Micro handling the explanations
PolicyLens reads an AWS IAM policy and tells you what is wrong with it in plain English, then hands back a tighter version you can actually use. Under the hood it runs a Python rule engine first, then calls Amazon Bedrock (Nova Micro) to explain the findings and write the fix. It is a small serverless app: Amplify for the frontend, API Gateway and Lambda for the backend, Bedrock for the reasoning.
Vision & What the App Does
IAM policies are quick to write and a pain to read.
"Action": "*" on "Resource": "*" looks about the same as a carefully scoped policy if you are skimming, and that gap is where a lot of the damage comes from. Doing a real review means remembering a pile of IAM detail: which actions let someone escalate, why iam:PassRole with no condition is a problem, how NotAction quietly widens what a statement allows.I built PolicyLens so I would not have to do that in my head every time. You give it a policy, by pasting the JSON, picking one of the built-in samples, or uploading a file, and you get back:
- Findings ranked from CRITICAL to LOW, worst first.
- A short explanation of each one in normal language.
- A line on what someone could actually do with the gap.
- A rewritten policy next to the original. If nothing is wrong, it says so instead of making something up.
AWS Services Used
Here is how a request moves through it:
┌───────────────────────────────────────────┐
│ Browser │
│ Static frontend on AWS Amplify │
└───────────────────────────────────────────┘
│ POST policy JSON
▼
┌───────────────────────────────────────────┐
│ Amazon API Gateway (HTTP API) │
└───────────────────────────────────────────┘
│
▼
┌───────────────────────────────────────────┐
│ AWS Lambda │
│ Layer 1: rule engine (Python) │
└───────────────────────────────────────────┘
│ findings passed in
▼
┌───────────────────────────────────────────┐
│ Amazon Bedrock — Nova Micro │
│ Layer 2: explanations + policy rewrite │
└───────────────────────────────────────────┘
│
▼
JSON response: ranked findings + rewrite
- AWS Amplify hosts the static frontend.
- Amazon API Gateway gives the Lambda a clean HTTPS endpoint to sit behind.
- AWS Lambda runs the backend. It does the rule checks itself, then calls Bedrock once per review.
- Amazon Bedrock is the AI layer, with no servers to manage.
- Amazon Nova Micro (
amazon.nova-micro-v1:0) handles the inference. It is fast and cheap, which matters when you are calling it on every single review.
How I Built It
The one rule I set early was that the code decides what is wrong and the model only explains it. That shaped everything else.
The rule engine is plain Python, about ten checks. It looks for the usual suspects: wildcard actions, wildcard resources on write calls, unconstrained
iam:PassRole , Allow paired with NotAction or NotResource, action combinations that add up to admin, sensitive calls with no condition attached, and a few tidiness checks. Most of the actual work was handling how inconsistent real IAM JSON is. Action and Resource can be a string or a list, a single statement might not be wrapped in a list, fields go missing, and if someone pastes broken JSON I wanted a clear error instead of a stack trace. None of this touches AWS, so I could test it locally.The Bedrock call comes second. It gets the policy plus the findings the rule engine already produced, and its job is to write the explanations and the fixed policy. It is not allowed to add findings of its own. Every finding it returns has to reference a rule ID the engine created, and anything else gets dropped before it reaches the screen. I also validate the rewritten policy as real IAM JSON before showing it. If Bedrock times out or throttles, you still get the rule engine's findings.
The annoying part was the plumbing between the browser and Lambda, the request body wrapping and the CORS handling, which I ended up doing directly in the handler so the console and the live site behaved the same way.
One thing I decided not to build: PolicyLens never asks for AWS credentials. No access key, no temporary token. If you want to check policies from a real account, there is a small read-only script you run yourself that exports them to a file you upload. Your keys stay on your machine. Doing anything else felt wrong for a tool about least privilege.
What I Learned
Putting the rule engine in front of the model was the decision that made the project work. The findings are trustworthy because they come from code I can test, not a model I have to second-guess. The layer that matters never touches AWS, so testing stayed quick. And when the model call fails there is still a real answer to show instead of an error. Locking the app's own IAM user down to a single Bedrock permission was a good reminder to practice what the tool preaches.
Links
-

-



Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article