How to Build a Serverless AI Agent on AWS for $0 Using Amazon Bedrock, Lambda, and Kiro
A step-by-step blueprint for building and deploying a production-ready AI agent using Amazon Bedrock (Amazon Nova), AWS Lambda, and Kiro while staying completely within the AWS Free Tier—complete with architecture and cost guardrails.
Why Most Cloud AI Prototypes Fail (And How to Fix It)
Many developers spin up their first generative AI project only to hit two walls: unexpected cloud bills from idle infrastructure and messy orchestration code. By pairing Amazon Bedrock with a strictly serverless AWS Free Tier stack and spec-driven development in Kiro, you can build a fast, reliable AI agent that costs $0/month at prototype scale.
Architecture Overview
Here is the lightweight, event-driven pipeline we are building:
1. API Layer (Amazon API Gateway): Receives user prompts over HTTPS and triggers compute only on demand.
2. Orchestration (AWS Lambda - Python 3.12): Runs stateless agent logic within the 1 million free monthly requests tier.
3. Foundation Model (Amazon Bedrock - Amazon Nova Lite): Handles reasoning and tool selection with sub-second latency and fractions-of-a-cent token pricing.
4. Memory Store (Amazon DynamoDB): Stores session history using on-demand capacity within the 25 GB free tier.
5. Safety & Cost Control (Amazon Bedrock Guardrails + AWS Budgets): Blocks prompt injection and alerts you before spending a cent.
2. Orchestration (AWS Lambda - Python 3.12): Runs stateless agent logic within the 1 million free monthly requests tier.
3. Foundation Model (Amazon Bedrock - Amazon Nova Lite): Handles reasoning and tool selection with sub-second latency and fractions-of-a-cent token pricing.
4. Memory Store (Amazon DynamoDB): Stores session history using on-demand capacity within the 25 GB free tier.
5. Safety & Cost Control (Amazon Bedrock Guardrails + AWS Budgets): Blocks prompt injection and alerts you before spending a cent.
Step 1: Structure Your Spec in Kiro
Instead of writing boilerplate from scratch, start with a clear specification in **Kiro** so your IAM least-privilege policies and Lambda handlers are generated cleanly:
* Define an input schema requiring `session_id` and `user_query`.
* Restrict the Lambda execution role strictly to `bedrock:InvokeModel` and `dynamodb:PutItem` / `dynamodb:Query`.
* Restrict the Lambda execution role strictly to `bedrock:InvokeModel` and `dynamodb:PutItem` / `dynamodb:Query`.
Step 2: Write the Serverless Agent Handler
Use the `converse` API in `boto3` so you can swap models on Amazon Bedrock without rewriting your code:
```python
import json
import boto3
import json
import boto3
bedrock = boto3.client(service_name="bedrock-runtime", region_name="us-east-1")
def lambda_handler(event, context):
body = json.loads(event.get("body", "{}"))
user_prompt = body.get("prompt", "Explain serverless in one line.")
body = json.loads(event.get("body", "{}"))
user_prompt = body.get("prompt", "Explain serverless in one line.")
response = bedrock.converse(
modelId="amazon.nova-lite-v1:0",
messages=[{"role": "user", "content": [{"text": user_prompt}]}],
inferenceConfig={"maxTokens": 300, "temperature": 0.3}
)
modelId="amazon.nova-lite-v1:0",
messages=[{"role": "user", "content": [{"text": user_prompt}]}],
inferenceConfig={"maxTokens": 300, "temperature": 0.3}
)
reply = response["output"]["message"]["content"][0]["text"]
return {
"statusCode": 200,
"headers": {"Content-Type": "application/json"},
"body": json.dumps({"response": reply})
}
return {
"statusCode": 200,
"headers": {"Content-Type": "application/json"},
"body": json.dumps({"response": reply})
}
Step 3: Lock Down Your Free Tier Costs
Before sharing your live demo link, always enable two safeguards:
Zero-Spend AWS Budget: Set a monthly budget alert at $1.00 (or $0.01 for pure Free Tier services) in the Billing console.
API Gateway Throttling: Cap burst limits at 5 requests/second so a viral post never turns into a surprise bill.
Key Lessons Learned
Start with Nova Lite before scaling up: For 80% of routing and summarization tasks, amazon.nova-lite-v1:0 delivers near-instant responses at a fraction of the cost of larger frontier models.
Keep state out of compute: Storing just the last 5 conversation turns in DynamoDB keeps token payloads small and latency under 800 ms.
What are you building on AWS right now? Drop your architecture or questions in the comments below—I would love to check out your projects and exchange feedback!
Before sharing your live demo link, always enable two safeguards:
Zero-Spend AWS Budget: Set a monthly budget alert at $1.00 (or $0.01 for pure Free Tier services) in the Billing console.
API Gateway Throttling: Cap burst limits at 5 requests/second so a viral post never turns into a surprise bill.
Key Lessons Learned
Start with Nova Lite before scaling up: For 80% of routing and summarization tasks, amazon.nova-lite-v1:0 delivers near-instant responses at a fraction of the cost of larger frontier models.
Keep state out of compute: Storing just the last 5 conversation turns in DynamoDB keeps token payloads small and latency under 800 ms.
What are you building on AWS right now? Drop your architecture or questions in the comments below—I would love to check out your projects and exchange feedback!
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article