๐Ÿ“˜ Fix My Policy: A Secure Legal Rephraser App with Angular, AWS Lambda, API Gateway & CloudFront

Abhi NikamAbhi Nikam
3 min read

In this blog, we walk through the step-by-step development and deployment of "Fix My Policy," a smart legal rephraser tool. You'll learn how we:

  • Built the frontend in Angular

  • Used Docker + Python for the backend

  • Integrated OpenRouter AI

  • Deployed via AWS Lambda & API Gateway

  • Delivered globally via CloudFront

๐Ÿ”— Live Demo: https://d3lvm4sqaobhu9.cloudfront.net/text

This guide is structured as if you were doing it yourself, step by step.


๐Ÿ”ง Step 1: Frontend Development with Angular

๐Ÿ›  Features:

  • Paste text or upload .pdf, .docx, .txt files

  • Displays result in "Plain English", "Risks", and "Suggestions"

๐Ÿงฑ Components:

  • TextInputComponent

  • DocumentUploadComponent

  • Shared ResultService for communication

โœ… Build Angular App:

ng build --configuration production

This outputs to dist/fix-my-policy/.


๐Ÿง  Step 2: Backend with Python + OpenRouter AI

We wrote the backend in Python that:

  • Accepts text/file via POST

  • Uses pdfplumber, docx, and cgi to extract content

  • Sends prompt to OpenRouter AI (e.g., DeepSeek, Mixtral)

  • Returns AI-generated JSON explanation

๐Ÿณ Dockerfile:

FROM public.ecr.aws/lambda/python:3.10
COPY requirements.txt ./
RUN pip install -r requirements.txt -t .
COPY app.py .
CMD ["app.lambda_handler"]

๐Ÿ“ฆ Build & Push to ECR:

docker build -t fix-my-policy-lambda .
aws ecr create-repository --repository-name fix-my-policy-lambda
aws ecr get-login-password | docker login --username AWS --password-stdin <your-account-id>.dkr.ecr.us-east-1.amazonaws.com
docker tag fix-my-policy-lambda <your-ecr-uri>:latest
docker push <your-ecr-uri>:latest

๐Ÿš€ Step 3: Deploy as AWS Lambda (Docker)

  • Create a Lambda function from container image

  • Use the pushed ECR image


๐Ÿ”— Step 4: Expose via API Gateway

  • Create a REST API using API Gateway

  • Integrate it with your Lambda function

  • Enable CORS (POST + OPTIONS)

  • Test the endpoint using Postman or Angular frontend


๐Ÿ—ƒ๏ธ Step 5: Upload Angular App to AWS for Hosting

We used AWS CloudShell to upload our Angular app to S3.

โœ… In Your Angular Project:

ng build --configuration production
zip -r fix-my-policy.zip ./dist/fix-my-policy/*

โœ… In AWS CloudShell:

# Upload fix-my-policy.zip using CloudShell UI
unzip fix-my-policy.zip -d fix-my-policy
aws s3 sync fix-my-policy/dist/fix-my-policy/browser/ s3://fix-my-policy-frontend --delete

๐Ÿงฑ Setup S3 Bucket:

aws s3api create-bucket --bucket fix-my-policy-frontend --region us-east-1
aws s3 website s3://fix-my-policy-frontend/ --index-document index.html --error-document index.html
aws s3api put-bucket-policy --bucket fix-my-policy-frontend --policy '...'

๐ŸŒ Step 6: Serve App Globally with CloudFront

We used a script to create a CloudFront distribution that points to our S3 site.

๐Ÿ“œ create-cloudfront.sh:

#!/bin/bash
BUCKET_NAME="fix-my-policy-frontend"
REGION="us-east-1"
ORIGIN_DOMAIN="$BUCKET_NAME.s3-website-$REGION.amazonaws.com"

aws cloudfront create-distribution \
  --origin-domain-name "$ORIGIN_DOMAIN" \
  --default-root-object index.html \
  --query "Distribution.{Id:Id, DomainName:DomainName}" \
  --output json

โœ… Run It:

chmod +x create-cloudfront.sh
./create-cloudfront.sh

Get the DomainName like:

d3lvm4sqaobhu9.cloudfront.net

Visit:

https://d3lvm4sqaobhu9.cloudfront.net/text

โœ… Final Deployment Checklist

  • Angular app built

  • Backend Lambda Dockerized

  • Lambda deployed to API Gateway

  • Frontend uploaded via CloudShell

  • CloudFront created for global HTTPS


๐Ÿงพ Conclusion

"Fix My Policy" is a complete cloud-native, serverless app:

  • Angular for frontend

  • Python AI backend with Docker

  • API Gateway + Lambda for logic

  • S3 + CloudFront for secure delivery

  • Deployed entirely from the browser using CloudShell

No local AWS CLI or IAM configuration needed.

โœ… Enterprise-ready
โœ… Secure
โœ… Scalable
โœ… Fully Serverless

Let us know if you want the full GitHub repo or auto-deploy script!

0
Subscribe to my newsletter

Read articles from Abhi Nikam directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Abhi Nikam
Abhi Nikam