
Day 34: Amazon Bedrock – Building Generative AI Applications with Foundation Models
Day 34 of my 90-day AWS challenge: how Amazon Bedrock gives access to foundation models through one API, how Knowledge Bases, Guardrails, and Agents extend it, and how it differs from SageMaker AI.
Recap of Day 33
Yesterday I used SageMaker AI to build and deploy my own machine learning model. Training a model from scratch needs data, compute, and expertise. Generative AI offers another route: use a large, pre-trained foundation model that can already write, summarize, answer questions, and analyze images, and build an application around it. On AWS, that service is Amazon Bedrock.
What is Amazon Bedrock?
Bedrock is a fully managed service that gives access to foundation models from several providers through one API. There are no servers to manage and no models to host. The same IAM, networking, and logging tools from earlier days apply.
Key concepts
Concept | What it is |
|---|---|
Foundation model (FM) | A large pre-trained model, such as a text, image, or embedding model, available through Bedrock |
Prompt | The instruction and context I send to the model |
Token | A small chunk of text; models are usually priced by input and output tokens |
Converse API | A common API for chat-style calls across supported models, including multi-turn conversations, tool use, and streaming |
InvokeModel | The lower-level API that uses each model's own request format |
Playground | A console page for trying prompts without writing code |
Embeddings | Numbers that represent the meaning of text, used for search and RAG |
Calling a model
import boto3
client = boto3.client("bedrock-runtime", region_name="us-east-1")
response = client.converse(
modelId="<model-id>",
messages=[
{"role": "user", "content": [{"text": "Explain AWS Lambda in two sentences."}]}
],
inferenceConfig={"maxTokens": 300, "temperature": 0.3},
)
print(response["output"]["message"]["content"][0]["text"])Replace
<model-id> with a model that is available to my account in my Region. Setting maxTokens limits the length and the cost of each reply. AWS also provides SDKs for other languages, including Java.The main building blocks
Feature | What it does |
|---|---|
Knowledge Bases | Managed RAG (retrieval-augmented generation): it indexes my documents, usually from S3, into a vector store, finds the relevant passages for each question, and gives them to the model so answers use my own data |
Guardrails | Safety controls that filter harmful content, block denied topics, mask sensitive information such as personal data, and check that answers are grounded in the source |
Agents and AgentCore | Let a model plan steps and call tools and APIs to complete tasks, and provide a platform to run agents securely at scale |
Prompt management and caching | Version prompts, and reuse repeated prompt content to cut cost and latency |
Model customization | Adapt a model to my data with options such as fine-tuning, where supported |
Evaluation | Compare models and prompts on quality before choosing one |
What RAG solves
A model only knows what it was trained on, so it can't answer questions about my private documents and may make things up. RAG fixes that by:
- Splitting my documents into chunks and turning them into embeddings
- Storing them in a vector store
- Searching for the chunks closest to the user's question
- Adding those chunks to the prompt so the model answers from them
Bedrock vs. SageMaker AI
| Amazon Bedrock | Amazon SageMaker AI |
|---|---|---|
Main idea | Use existing foundation models through an API | Build, train, and deploy my own models |
Needs ML expertise | Little | More |
Infrastructure | None to manage | Notebooks, jobs, and endpoints to manage |
Best for | Chatbots, summarization, search, and content generation | Custom models on my own data and full control over training |
Security and governance
- IAM controls who can invoke which models and use which resources (Day 2)
- Traffic can stay off the public internet with VPC endpoints (PrivateLink) (Day 5)
- CloudTrail records model invocations (Day 20)
- Data and knowledge bases can be encrypted with KMS (Day 19)
- Depending on the model and Region, I may need to enable access in the Bedrock console before calling it
How it connects to earlier days
- Day 8 and 15: a Lambda function behind API Gateway is a common way to put a Bedrock-powered feature behind an API
- Day 22: Cognito can handle sign-in for the users of a generative AI app
- Day 4: S3 holds the documents for a knowledge base
- Day 26: cost tracking matters, because charges depend on tokens and any vector store
Responsible use
- Don't put sensitive or private data into prompts unless the service and settings are approved for it
- Check the outputs. Models can sound confident and still be wrong
- Use Guardrails and clear instructions, and test with unusual inputs
Cost
- On-demand use is billed per token (input and output), and prices differ widely between models
- Provisioned throughput reserves capacity for steady, heavy use
- Knowledge Bases also pay for the vector store, which can have a minimum running cost, so delete practice ones
- Check the pricing page and set budgets (Day 26) before experimenting
What I practiced today
- Opened the Bedrock console and checked which models were available to my account
- Tried several prompts in the Playground, and changed settings like temperature
- Called a model with the Converse API from a script, using a limited IAM permission
- Explored the setup options for Knowledge Bases and Guardrails
- Deleted anything I created, especially any vector store
Key takeaways
- Bedrock lets me build generative AI features without training or hosting a model
- RAG is how a model answers questions about my own data
- Treat prompts and outputs as part of the system: protect data, add guardrails, and verify answers
- Costs depend on tokens and supporting resources, so limit output length and delete practice resources
Up next: Day 35
Week 5 recap: Athena, Glue, Kinesis, Quick Sight, SageMaker AI, and Bedrock.
Learning AWS too? Follow along and share what you're building. #90DaysOfAWS
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article