This is the pattern: upload triggers AI which writes results. The same shape powers customer support bots, expense tracking, content moderation, and fraud detection at major companies.
You'll know it works when:
- You upload a PDF to the S3
uploads/folder - Within 10 seconds, a new row appears in your DynamoDB table
- That row contains: the extracted text, the overall sentiment, and the named entities (people, places, organizations)
Textract is NOT free tier indefinitely — but you get 1,000 free pages per month for the first 3 months. More than enough for testing. Just don't process the entire library of Congress today.
Same drill as Week 2 Lab 4 — you've done this twice already.
- S3 → Create bucket
- Name:
cloudwithshad-docs-<your-initials>-<random> - Region: same as everything else this bootcamp
- Block all public access: keep ON (Lambda accesses it, not the public)
- Click Create bucket
- Open the bucket → create a folder named
uploads/
It prevents accidental recursive triggers and keeps the bucket organized. We'll attach the Lambda trigger only to objects under uploads/.
DynamoDB is AWS's serverless NoSQL database. Perfect for this — you don't manage a server, you don't manage schema, you just write JSON.
- Navigate to DynamoDB → Tables → Create table
- Table name:
cloudwithshad-documents - Partition key:
document_id(String) - Leave all other settings as defaults (On-demand capacity, no sort key)
- Click Create table
That's it. Within 30 seconds the table is ready. No servers, no schema, no setup wizard for indexes.
For this app, our data is unstructured (text + entities + sentiment scores) and we don't need joins. DynamoDB shines: it's serverless (no idle cost), scales automatically, and accepts JSON natively. RDS would be overkill.
The Lambda function needs permissions to do five things: read from S3, call Textract, call Comprehend, write to DynamoDB, and write CloudWatch logs.
- IAM → Roles → Create role
- Trusted entity: AWS service
- Use case: Lambda
- Attach these policies (search and tick each):
AWSLambdaBasicExecutionRoleAmazonS3ReadOnlyAccessAmazonTextractFullAccessComprehendFullAccessAmazonDynamoDBFullAccess
- Role name:
cloudwithshad-docs-role - Create role
FullAccess policies are too broad for production. In real systems you'd create custom policies scoped to ONLY the specific table/bucket/service. For learning, FullAccess is fine.
- Lambda → Create function
- Author from scratch
- Function name:
cloudwithshad-doc-analyzer - Runtime: Python 3.12
- Architecture: x86_64
- Execution role: Use existing →
cloudwithshad-docs-role - Click Create function
Once created, scroll to the Code tab and paste this:
This version uses Amazon Comprehend for sentiment + entities. It's the most accurate, but Comprehend is not on the perpetual free tier — depending on your account it may need billing enabled and can cost a dollar or two. If you'd rather not upgrade your account, use Option B just below — it does the same job for free.
Don't want to enable billing or pay for Comprehend? Use this version instead. It keeps Textract (which has a free 1,000 pages/month window) but does the sentiment + entity analysis in plain Python inside the same Lambda — so it costs nothing beyond the Lambda free tier. Same architecture, same DynamoDB result, $0.
Paste this into your Lambda's Code tab instead of the Option A code:
1. Skip the Comprehend permission. In the IAM role step earlier, you can leave off ComprehendFullAccess — Option B never calls Comprehend. You only need S3 read, Textract, DynamoDB, and CloudWatch logs.
2. Same 60s timeout is fine. Only Textract makes a network call now; the Python analysis is instant.
Option B's analysis is simpler than Comprehend's machine-learning models — it uses word lists for sentiment and capitalisation for entities. It's perfect for learning the full pipeline at zero cost, and it's a great lesson in why managed AI services exist: Comprehend is more accurate because it's trained on huge datasets. When you're ready to spend a little (or in the AI course), swapping Option B for Comprehend — or for a Bedrock model — is a one-function change. The architecture you built stays exactly the same.
Click Deploy.
Configuration → General configuration → Edit. Change timeout from 3 seconds to 60 seconds. Textract + Comprehend calls can take 5-15s on bigger documents.
Now add the S3 trigger:
- In the Lambda function page, click "+ Add trigger"
- Select S3
- Bucket: your
cloudwithshad-docs-...bucket - Event type: All object create events
- Prefix:
uploads/ - Tick the recursive acknowledgement
- Click Add
The moment of truth.
Find a real document to test with. Good options:
- A receipt photo from your phone
- A screenshot of an article or news page
- A simple PDF (under 5 MB to start)
- Your CV (works great — lots of entities to detect!)
- Open S3 → your bucket →
uploads/ - Click Upload and drop in the file
- Wait 10-15 seconds
- Open DynamoDB → Tables → cloudwithshad-documents → Explore items
- Click Scan
- You should see a new row with the extracted text, sentiment, and entities!
Capture the DynamoDB item showing the sentiment + entities pulled from your document. Post it in the cohort group with the caption "Lab 7 done — AI just read my CV!" 🎉
CloudWatch → Log groups → /aws/lambda/cloudwithshad-doc-analyzer. The error will tell you everything. Most common: missing permissions on the IAM role, or the Lambda timing out (bump timeout to 60s).
⚠ Cleanup checklist
- S3 bucket: empty it, then delete
- Lambda function: Lambda → cloudwithshad-doc-analyzer → Delete
- DynamoDB table: DynamoDB → Tables → cloudwithshad-documents → Delete
- IAM role: IAM → Roles → cloudwithshad-docs-role → Delete
- CloudWatch log group: /aws/lambda/cloudwithshad-doc-analyzer → Delete (optional)
The Textract free tier is generous — 1,000 pages/month for 3 months. After that it's ~$1.50 per 1,000 pages. You won't see surprise bills unless you process thousands of documents. DynamoDB is free up to 25 GB of storage.
Lab 7 complete!
You just chained 4 AWS services to build a real AI pipeline. This is the foundation of every modern "smart document" tool out there.
Next: Lab 8 — Your AI Capstone Project