AWS Builder Center
Scoring Every Loan, Not a Sample: A Serverless Loan Risk Platform on AWS

Scoring Every Loan, Not a Sample: A Serverless Loan Risk Platform on AWS

How we built LoanLens for the First Commit hackathon: S3, EventBridge, Step Functions and Lambda score every loan in a monthly tape into DynamoDB, with Cedar policies for approvals, a Bedrock-first AI copilot, and about $0 spent. Includes the bugs that cost us time and what we would do next.

hERE tO wIN
Every month, a lender receives a loan tape: thousands of rows, one per loan per month. Nobody can read all of it, so teams check a small sample and hope the risky loans are in it. For the First Commit hackathon, my teammate Abhishek and I built LoanLens, which scores every loan the moment the file lands. It runs entirely on serverless AWS.

Architecture

Uploading a file is the only trigger.
  • The browser gets a presigned URL and uploads straight to S3, so API Gateway's payload limit never applies.
  • The S3 event goes through EventBridge to a Step Functions workflow.
  • The workflow calls a container Lambda (arm64) running LightGBM models and a rule engine, and writes every scored loan to DynamoDB.
  • If a run finds high-risk loans, Step Functions publishes to SNS using its native SDK integration, with no extra Lambda.
  • The React dashboard on Amplify talks to API Gateway, which fronts Lambdas for the portfolio, a stress test, a policy gate and a copilot.
Nothing runs when nobody is using it: no EC2, no SageMaker endpoint, no OpenSearch.

Cedar for approvals

Who may approve a loan is a policy, not a pile of if-statements. I used Cedar, AWS's open-source policy language, running in Lambda through  @cedar-policy/cedar-wasm . A junior underwriter is denied above their limit, and only the risk committee can override a flagged record.
Two things I learned: Cedar has no floating-point numbers, so risk and loan-to-value travel as integer percentages. And the  cedar-policy  package on PyPI is an unrelated placeholder; the official engine is the npm package.

A copilot that never hides which model answered

The copilot builds its facts first, from aggregates over every scored loan, and only then asks a model to explain them. It tries Bedrock first, then an OpenAI-compatible model whose key sits in SSM Parameter Store as a SecureString, then a deterministic template. Every answer says which one produced it.
Our new account stayed in Bedrock's account verification for the whole event. Building the copilot as a chain of providers meant the product kept working.

What went wrong

The most useful lessons came from failures:
  • The Python 3.11 Lambda image is Amazon Linux 2, so current scipy and LightGBM wheels wouldn't install. Switching to the Python 3.12 image (Amazon Linux 2023) fixed it.
  • DynamoDB rejects Python floats and NaN. Our first live run failed on exactly that, and I kept it as a regression test.
  • Step Functions retries only Lambda service errors. A malformed upload is deterministic, so it fails once with a message naming the missing columns.

Cost

On-demand DynamoDB, 7-day log retention, a 7-day expiry on uploads and API throttling kept spend near zero on a $100 credit budget.

What I would do next

Add authentication with Cognito and load-test larger tapes. LoanLens is a prototype on synthetic data, and its output is a recommendation, not a decision.
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