Amazon Bedrock Deep Dive · lab exercise
Exercise 1: your first Amazon Bedrock Converse call
Part of Amazon Bedrock Deep Dive (BDR-101), with lesson 2-1, the Converse API. You do this in your own AWS account; Gazeek gives no AWS access.
Cost: one short call to Amazon Nova Micro, a small fraction of a cent (about 40 tokens). Nothing is created, so there is nothing to clean up.
Before you start
- An AWS account you can use, with credentials on your machine (
aws configure, or AWS IAM Identity Center). - Permission to call
bedrock:InvokeModelin us-east-1. Most models, Nova Micro included, need no access request: access starts on the first call. - Python 3.10 or later.
Steps
-
Make a folder and a virtual environment, and install boto3:
python3 -m venv .venv && source .venv/bin/activate pip install boto3 -
Save
converse.pyin the folder. The heart of it:client = boto3.client("bedrock-runtime", region_name="us-east-1") response = client.converse( modelId="amazon.nova-micro-v1:0", system=[{"text": "You are a helpful assistant. Answer in one sentence."}], messages=[{"role": "user", "content": [{"text": "What is Amazon Bedrock?"}]}], inferenceConfig={"maxTokens": 200, "temperature": 0.2}, ) print(response["output"]["message"]["content"][0]["text"]) -
Run it:
python converse.py
What you should see
One sentence from the model, then the call's details, like this (Gazeek's test run, 27 Nov 2026):
Amazon Bedrock is a foundation for building and deploying high-quality, secure, and scalable generative AI models.
stopReason: end_turn
tokens: 17 in, 23 out
latencyMs: 411
Look closely at that answer: it isn't quite right. Bedrock gives you access to models; it doesn't build them. Small models are fast and cheap, and they get things wrong. That is why later parts add Knowledge Bases (answers grounded in your documents) and Guardrails.
Try this
- Change
MODEL_IDto another model you can call (check its model card for the ID and Region) and run it again. The rest of the code stays the same: that is the point of Converse. - Set
maxTokensto 5 and run it:stopReasonbecomesmax_tokens.
If it fails
AccessDeniedException: your IAM user or role can't callbedrock:InvokeModelon that model.ValidationExceptionabout the model ID: check the ID on the model card, including the version (-v1:0).ThrottlingException: wait and retry; the SDK retries for you a few times.
Clean up
Nothing to clean up: a Converse call creates no resources.
What you learned
One API call, converse, with a model ID, a system prompt, a message and inference settings; the answer, the stop
reason and the token usage you pay for.
converse.py
"""Exercise 1: your first Amazon Bedrock Converse call (Amazon Bedrock Deep Dive, BDR-101).
Run: python converse.py
Needs: Python 3.10+, boto3, AWS credentials for an account that can call Bedrock in us-east-1.
Cost: one short call to Amazon Nova Micro, a small fraction of a cent.
"""
import boto3
MODEL_ID = "amazon.nova-micro-v1:0" # check the model card: docs.aws.amazon.com/bedrock/latest/userguide/model-cards.html
REGION = "us-east-1"
client = boto3.client("bedrock-runtime", region_name=REGION)
response = client.converse(
modelId=MODEL_ID,
system=[{"text": "You are a helpful assistant. Answer in one sentence."}],
messages=[{"role": "user", "content": [{"text": "What is Amazon Bedrock?"}]}],
inferenceConfig={"maxTokens": 200, "temperature": 0.2},
)
print(response["output"]["message"]["content"][0]["text"])
print()
print("stopReason:", response["stopReason"])
usage = response["usage"]
print(f"tokens: {usage['inputTokens']} in, {usage['outputTokens']} out")
print("latencyMs:", response["metrics"]["latencyMs"])