AWS Builder Center
Stop Typing Receipts: Build an AI Expense Tracker on AWS

Stop Typing Receipts: Build an AI Expense Tracker on AWS

Everyone has a drawer, a bag, or a phone gallery full of receipts. Typing them into a spreadsheet by hand is boring and full of mistakes. So I asked a simple question: can I take a photo of a receipt and let AWS do the rest? The answer is yes, and you can build it with a few managed services and no servers to maintain. This article walks through the idea, the architecture, and how to build it step by step.

Computer Engineering Undergraduate

The problem

Small shops, freelancers, and students all share the same pain: receipts and invoices arrive as photos or PDFs, and someone has to copy the vendor, date, items, and total into a sheet. It is slow, and one wrong digit can ruin a monthly report.

The solution in one sentence

Upload a receipt image to Amazon S3, and a serverless pipeline automatically reads it, extracts the key fields, and saves clean data you can search or download.

The architecture

Here is how the pieces fit together:
  1. Amazon S3 receives the uploaded receipt photo.
  1. S3 event trigger starts an AWS Lambda function automatically when a new file arrives.
  1. Amazon Textract reads the image and extracts text, and its expense analysis feature pulls out fields like vendor, date, total, and line items.
  1. Amazon Bedrock (optional) cleans the result and assigns a category, such as food, transport, or office supplies.
  1. Amazon DynamoDB stores each receipt as a record.
  1. Amazon SNS or SES sends you a summary email, or a flag when something looks wrong.
  1. A simple dashboard or CSV export lets you view and download everything.
No servers to patch, no machines running all day. You pay only when a receipt is processed.




Step-by-step build

Step 1: Create the storage

Make an S3 bucket with Block Public Access turned on. Add two folders (prefixes):  incoming/  and  processed/ .

Step 2: Write the Lambda function

Create a Lambda function in Python that runs when a new file lands in  incoming/ . It calls Textract’s expense analysis on the file and receives structured fields.


Starter Lambda function (Python)

This reads a receipt from S3 with Textract, checks confidence, and saves the result to DynamoDB.
python
import os
import uuid
import boto3
from decimal import Decimal
from datetime import datetime, timezone
from urllib.parse import unquote_plus

textract = boto3.client("textract")
dynamodb = boto3.resource("dynamodb")
table = dynamodb.Table(os.environ["TABLE_NAME"])

MIN_CONFIDENCE = 90 # below this, flag for human review
WANTED = {
"VENDOR_NAME": "vendor",
"INVOICE_RECEIPT_DATE": "date",
"TOTAL": "total",
}

def lambda_handler(event, context):
record = event["Records"][0]["s3"]
bucket = record["bucket"]["name"]
key = unquote_plus(record["object"]["key"]) # S3 keys arrive URL-encoded

response = textract.analyze_expense(
Document={"S3Object": {"Bucket": bucket, "Name": key}}
)

item = {
"receipt_id": str(uuid.uuid4()),
"source_file": f"s3://{bucket}/{key}",
"processed_at": datetime.now(timezone.utc).isoformat(), "vendor": "",
"date": "",
"total": "",
"needs_review": False,
}
confidences = {}

for doc in response["ExpenseDocuments"]:
for field in doc["SummaryFields"]:
field_type = field.get("Type", {}).get("Text")
if field_type in WANTED and "ValueDetection" in field:
name = WANTED[field_type]
if item[name]: # keep the first match only
continue
item[name] = field["ValueDetection"]["Text"]
confidences[name] = field["ValueDetection"]["Confidence"]

# Quality check: missing fields or low confidence -> needs review
for name in WANTED.values():
if not item[name] or confidences.get(name, 0) < MIN_CONFIDENCE:
item["needs_review"] = True

item["confidence"] = {k: Decimal(str(round(v, 1))) for k, v in confidences.items()}

table.put_item(Item=item)
return {"receipt_id": item["receipt_id"], "needs_review": item["needs_review"]}
Setup notes:
  • Set an environment variable  TABLE_NAME  to your DynamoDB table name. The table’s partition key should be  receipt_id  (String).
  • Add an S3 event trigger on the  incoming/  prefix for object-created events.
  • Set the Lambda timeout to about 30 seconds.
  • The role needs only three permissions:  s3:GetObject  on your bucket,  textract:AnalyzeExpense , and  dynamodb:PutItem  on your table.
  • Test with a clear JPG or PNG receipt first.

Step 3: Set minimal permissions

Give the Lambda role only what it needs: read from the bucket, call Textract, and write to DynamoDB. Nothing more.

Step 4: Save the results

Store the vendor, date, total, category, and the original file name in a DynamoDB table. Keep a link back to the original image so every number can be checked.

Step 5: Add a quality check

Textract returns confidence scores. If the total or date has low confidence, mark the receipt as “needs review” instead of trusting it automatically.

Step 6: Send a summary

Use SES or SNS to email yourself a short message: “5 receipts processed, 1 needs review.”

Step 7: Export

Add a small function that exports the table to CSV, so you can open the data in Excel or Google Sheets.

Making it production-minded (the DevOps part)

This is where a small project becomes a great portfolio piece:
  • Infrastructure as code: define everything in CloudFormation, SAM, or Terraform so the whole system can be created or deleted with one command.
  • Monitoring: use CloudWatch logs and alarms to catch failed runs.
  • Error handling: send failed files to a dead-letter queue so nothing is lost.
  • CI/CD: store the code in Git and deploy changes automatically.
  • Cost control: set a budget alert and a lifecycle rule to archive old receipts.

What it costs

For a learning project with a few dozen receipts a month, the cost is usually very small, since Lambda, S3, and DynamoDB have generous free tiers. Textract is billed per page, so check current pricing and set a billing alert before testing with large batches.

Real-world uses

  • Freelancers tracking business expenses
  • Small shops digitizing supplier invoices
  • Students managing a monthly budget
  • Teams collecting travel claims

Limitations and lessons

  • Blurry or crumpled receipts reduce accuracy, so photo quality matters.
  • Never trust a total blindly. Confidence scores and a human review step prevent costly mistakes.
  • Privacy matters. Receipts can contain personal data, so encrypt the bucket and limit who can access it.
  • Start simple. Get S3, Lambda, and Textract working first, and add the extras later.

Final thoughts

This project covers storage, AI, serverless, security, and automation in one build. It shows that practical AI doesn’t have to mean training huge models. Sometimes the best solution is connecting the right managed services to solve a boring everyday problem.

Your turn

Would you use a tool like this for your own receipts or invoices? Tell me in the comments what document you’d want to automate next: invoices, ID forms, handwritten notes, or something else. The most requested one becomes my next article.
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