AWS Builder Center
Build Your First Generative AI Chatbot with AWS Bedrock (in Minutes)

Build Your First Generative AI Chatbot with AWS Bedrock (in Minutes)

Learn how to use AWS Bedrock to build a simple Generative AI chatbot and extend it with your own documents using Amazon S3.

Backend Developer | Building in Cloud & DevOps

Introduction

Generative AI is no longer reserved for research labs and large tech companies. With AWS Bedrock, developers of all levels can access powerful foundation models like Anthropic Claude, Mistral, and Amazon Titan—without managing any infrastructure. Bedrock allows you to prototype quickly, integrate with your existing AWS services, and scale when you are ready.
In this guide, I will show you how to build a simple chatbot using AWS Bedrock and extend it with document-based knowledge using Amazon S3.

Step 1: Understand AWS Bedrock

AWS Bedrock is a fully managed service that provides API access to different foundation models. Instead of training or deploying large language models yourself, you can:
  • Call models through an API.
  • Choose from multiple providers in one place.
  • Use AWS-native integrations (S3, DynamoDB, Lambda).
This means faster development, lower upfront costs, and less operational overhead.

Step 2: Getting Started

Before coding, make sure you have:
  1. AWS Account with Bedrock enabled in your region.
  1. An IAM role or user with the policy  AmazonBedrockFullAccess .
  1. Installed the Python AWS SDK (boto3):
pip install boto3

Step 3: Your First Chatbot

Here’s a minimal example of sending a prompt to Bedrock:
import boto3
import json

# Create a Bedrock client
client = boto3.client("bedrock-runtime", region_name="us-east-1")

# Define the prompt
prompt = "Hello! Can you give me a short summary of AWS Bedrock?"

# Call the Claude v2 model
response = client.invoke_model(
modelId="anthropic.claude-v2",
body=json.dumps({
"prompt": prompt,
"max_tokens_to_sample": 150
}),
contentType="application/json", # Required: input format
accept="application/json" # Required: output format
)

# Print the model’s response
print(response["body"].read().decode("utf-8"))

✅ With just a few lines, you now have a chatbot that generates text using Claude-v2.



Step 4: Add Your Own Knowledge (RAG)

Generative AI is more powerful when it uses your data.
  • Upload documents (PDFs, TXT) into Amazon S3.
  • Create a Bedrock Knowledge Base connected to those documents.
  • Ask questions, and the model retrieves relevant context before answering.
Example use cases:
  • Customer support bots answering from product manuals.
  • Company knowledge assistants using internal docs.
  • Research helpers for large PDF collections.



Step 5: Cost and Best Practices

Bedrock charges per token (input + output). Tips to optimize cost:
  • Keep prompts concise.
  • Set a  max_tokens  limit.
  • Cache or reuse frequent responses.
You can also set up CloudWatch alarms to monitor usage and avoid unexpected charges.



Step 6: Build a Real Application

Once your prototype works, you can scale it into a real application:
  • API Gateway + Lambda → expose your chatbot as a REST API.
  • DynamoDB → store user history for personalization.
  • CI/CD with CodePipeline or GitHub Actions → automate deployments.



Next Steps

Now that you have a working chatbot, try connecting it with Amazon API Gateway or extending it with a Knowledge Base. This will take your prototype one step closer to production.
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