Ravindra BagaleCourses & study guides Track your progress

Amazon Bedrock for Beginners: Your First Gen AI App on AWS

Generative AI course · Chapter 46 · Estimated reading time: 12 minutes

Until now you have called AI models from Google and OpenAI with an API key. Many companies in India run their systems on AWS, and they want their AI to run there too: same login, same bills, same security rules. Amazon Bedrock is the AWS service that gives you many foundation models (from Amazon, Anthropic, Meta, Mistral and others) through one API, without managing any servers. In this chapter you will try a model in the Bedrock playground, make your first Python call with boto3 and the Converse API, test your code for free with no AWS account, and estimate the cost and set limits before anyone uses your app. Facts were checked on the AWS pages on 19 October 2026.

What you will learn in this chapter

  • What Amazon Bedrock is, and why companies use it
  • Regions, model IDs and model access, in plain words
  • Example 1: a prompt in the Bedrock text playground
  • Example 2: your first Python call with boto3 and Converse
  • How to test Bedrock code offline, with no cost
  • Example 3: a cost and quota check before you launch
  • The safety settings to switch on first

1. Suppose a library wants a welcome-message helper

Suppose the City Library team runs its member records on AWS. They want a small tool that writes a friendly welcome message for each new member. Their IT head says: "Fine, but the data must stay inside our AWS account, billing must come on our AWS bill, and access must use our IAM roles."

That is the case for Bedrock. The same Python code style they use for S3 or EC2 (boto3) can now call an AI model.

2. Bedrock in plain words

  • Foundation models, one API: Bedrock offers models from several providers. The Converse API lets you call most of them with the same code, so you can switch models by changing one ID.
  • Region: like every AWS service, Bedrock runs in Regions. Not every model is in every Region. The AWS getting-started pages use US East (N. Virginia), us-east-1; check the model catalog in your chosen Region.
  • Model ID: the exact name your code uses, such as amazon.nova-micro-v1:0. Copy it from the Model catalog; do not type it from memory.
  • Model access: in commercial Regions, most models are enabled on first use from the model catalog. Anthropic models need a one-time use-case form first.
  • Pay per use: you pay for the tokens you send and receive, at the price for that model and Region on the Bedrock pricing page.
  • Free plan accounts: new AWS accounts on the Free plan can use Bedrock with their credits, but cross-Region inference is not supported on the Free plan. AWS also gives USD 20 of extra credit for trying a prompt in the Bedrock text playground (part of the up to USD 200 new-account credits).
Your first Bedrock app in five steps Steps from top to bottom: 1 Pick a Region and model, Copy the ID from the catalog; 2 Try the playground, Compare two small models; 3 Call it from Python, boto3 and the Converse API; 4 Test offline first, Stubber checks every parameter; 5 Cost and limits, Budget alert, quotas, maxTokens. 1Pick a Region and modelCopy the ID from the catalog 2Try the playgroundCompare two small models 3Call it from Pythonboto3 and the Converse API 4Test offline firstStubber checks every parameter 5Cost and limitsBudget alert, quotas, maxTokens

Your first Bedrock app: playground, code, offline test, cost check

3. Worked example 1: a prompt in the playground

Steps:

  1. Sign in to the AWS console with an IAM user or role (not the root user; see the AWS chapter AWS IAM User, Root User and MFA: Launch Your First EC2 Instance).
  2. Choose your Region at the top right.
  3. Open Amazon Bedrock. In the left menu, choose Model catalog.
  4. Pick a small, low-cost text model, for example Amazon Nova Micro, and choose Open in playground.
  5. Type the prompt below and choose Run.
You are a friendly library assistant. Write a 2-line welcome message for a new member
named [member name]. Mention that they can borrow 4 books at a time. Keep it under 40 words.

Expected output (yours will be similar, not the same): "Welcome to City Library, [member name]! You can now borrow up to 4 books at a time, so pick a few favourites and enjoy reading." The playground also shows the number of input and output tokens; note them for the cost check in Example 3.

Try the same prompt with a second model from the catalog and compare the answers. This is how you choose a model: the cheapest one that does the job well.

4. Worked example 2: your first Python call

Before you start:

  1. Install the AWS CLI and sign in with your IAM user's keys (see our guide How to Install and Configure AWS CLI (Windows, Mac, Linux)), or create a short-term Bedrock API key in the console.
  2. Give your IAM user permission to call bedrock:InvokeModel on the model you use, and nothing more.
  3. Install boto3: pip install --upgrade boto3. (A Bedrock API key in the AWS_BEARER_TOKEN_BEDROCK variable needs boto3 1.39.0 or later.)
# Your first Amazon Bedrock call with the Converse API (needs AWS credentials or a Bedrock API key).
import boto3
from botocore.exceptions import ClientError

client = boto3.client("bedrock-runtime", region_name="us-east-1")   # N. Virginia; the model must be offered in your Region
MODEL_ID = "amazon.nova-micro-v1:0"                                 # copy the exact ID from the Model catalog

try:
    response = client.converse(
        modelId=MODEL_ID,
        messages=[{"role": "user", "content": [{"text": "Write a 2-line welcome message for a new library member."}]}],
        inferenceConfig={"maxTokens": 200, "temperature": 0.5},
    )
    print(response["output"]["message"]["content"][0]["text"])
    print("Tokens in/out:", response["usage"]["inputTokens"], "/", response["usage"]["outputTokens"])
except ClientError as e:
    print("ERROR:", e.response["Error"]["Code"], "-", e.response["Error"]["Message"])

Expected output (yours will be similar, not the same):

Welcome to City Library! Your card is ready, so borrow up to 4 books and enjoy your reading.
Tokens in/out: 19 / 24

Common errors:

  • AccessDeniedException: your IAM user lacks bedrock:InvokeModel, or the model needs its access form (Anthropic).
  • ValidationException about on-demand throughput: that model must be called through an inference profile ID from the console (cross-Region, which the Free plan does not allow). Pick a model that runs on demand in your Region.
  • ThrottlingException: you hit a quota; wait and retry, or see Example 3.

Test your code for free, with no AWS account. botocore's Stubber replaces the real reply with a fake one, but still checks every parameter against the real Bedrock API definition:

import boto3
from botocore.stub import Stubber
from botocore.exceptions import ParamValidationError

client = boto3.client("bedrock-runtime", region_name="us-east-1",
                      aws_access_key_id="DUMMY", aws_secret_access_key="DUMMY")
request = {"modelId": "amazon.nova-micro-v1:0",
           "messages": [{"role": "user", "content": [{"text": "Write a 2-line welcome message."}]}],
           "inferenceConfig": {"maxTokens": 200, "temperature": 0.5}}
fake_reply = {"output": {"message": {"role": "assistant", "content": [{"text": "(fake reply for the test)"}]}},
              "stopReason": "end_turn", "usage": {"inputTokens": 12, "outputTokens": 9, "totalTokens": 21},
              "metrics": {"latencyMs": 1}}
with Stubber(client) as stub:
    stub.add_response("converse", fake_reply, request)
    r = client.converse(**request)
    print("1. Correct request accepted. Reply text:", r["output"]["message"]["content"][0]["text"])
    print("   Tokens in/out:", r["usage"]["inputTokens"], "/", r["usage"]["outputTokens"])

bad = {**request, "inferenceConfig": {"maxTokens": "200"}}     # a common mistake: a number sent as text
try:
    client.converse(**bad)
except ParamValidationError as e:
    print("2. Mistake caught before any cost:", str(e).splitlines()[-1].strip())

Real output (19 October 2026, boto3 1.43; the reply text is fake by design):

1. Correct request accepted. Reply text: (fake reply for the test)
   Tokens in/out: 12 / 9
2. Mistake caught before any cost: Invalid type for parameter inferenceConfig.maxTokens, value: 200, type: <class 'str'>, valid types: <class 'int'>

Ravindra Bagale's Tip

The mistake: testing a new AI feature straight on the live account, with admin keys, inside a loop that calls the model for every row of a big file. One bug and the bill jumps overnight. Test the code offline with Stubber first, then run it on 5 rows with a user that may call only one model, and set a budget alert before you run it on everything.

5. Worked example 3: a cost and quota check before launch

Bedrock bills by tokens. Before launch, estimate a month with your own numbers. The prices in this script are dummy numbers; copy the real input and output prices for your model and Region from the Amazon Bedrock pricing page.

PRICE_IN_PER_1K = 0.00010    # DUMMY input price in USD per 1,000 tokens
PRICE_OUT_PER_1K = 0.00040   # DUMMY output price in USD per 1,000 tokens
USD_TO_INR = 88              # DUMMY exchange rate; use today's rate

requests_per_day, in_tokens, out_tokens, days = 300, 400, 150, 30
monthly_in = requests_per_day * in_tokens * days
monthly_out = requests_per_day * out_tokens * days
usd = monthly_in / 1000 * PRICE_IN_PER_1K + monthly_out / 1000 * PRICE_OUT_PER_1K
print(f"Requests a month: {requests_per_day * days:,}")
print(f"Tokens a month: {monthly_in:,} in + {monthly_out:,} out")
print(f"Estimated cost: USD {usd:.2f} (about Rs {usd * USD_TO_INR:,.0f}) with the DUMMY prices")
print(f"A USD 1 budget alert would fire after about {1 / usd * 30:.0f} days at this rate")

Real output (with the dummy prices):

Requests a month: 9,000
Tokens a month: 3,600,000 in + 1,350,000 out
Estimated cost: USD 0.90 (about Rs 79) with the DUMMY prices
A USD 1 budget alert would fire after about 33 days at this rate

Then set 3 limits:

  1. A budget alert in AWS Budgets, for example USD 5 a month, emailed to you. Our guide How to Set Up an AWS Billing Alarm and Budget (Free Tier) shows the steps.
  2. Quotas: open Service Quotas → Amazon Bedrock and look at the requests-per-minute and tokens-per-minute values for your model. Your app should handle ThrottlingException by waiting and retrying.
  3. maxTokens in every call, so one answer can never be very long.

6. Safety settings to switch on first

  • IAM least privilege: your app's role may call only bedrock:InvokeModel on the models it uses.
  • No secrets in prompts: never paste keys or passwords into a prompt.
  • Guardrails: Bedrock has a Guardrails feature to block topics, filter harmful content and mask personal data such as phone numbers. Add one before real users arrive.
  • Logging: turn on model invocation logging if your company needs an audit trail, and keep those logs private.
  • Clean up: delete test API keys and users you no longer need.

7. Beginner mistakes and quick fixes

Mistake What happens Quick fix
Using the root user Huge risk if keys leak An IAM user or role with Bedrock-only permission
Typing the model ID from memory ValidationException Copy it from the Model catalog
Wrong Region "Model not found" or access errors Check the model is offered in your Region
No maxTokens Long, costly answers Set maxTokens on every call
No budget alert Surprise bill AWS Budgets alert before launch
Testing only on the live account Every bug costs money Stubber tests first, then 5 real rows

8. Try at home

Try at home

Task 1: the playground

  1. Open the Bedrock model catalog in your Region.
  2. Run the welcome prompt on 2 small models.
  3. Note the tokens and pick the one you prefer.

Task 2: the free offline test

  1. Install boto3 and run the Stubber script.
  2. Change temperature to the text "high".
  3. Read the error it catches.

Task 3: your cost sheet

  1. Copy real prices for your model from the Bedrock pricing page.
  2. Put your own request counts into the cost script.
  3. Set an AWS Budgets alert at a number you are comfortable with.

Recap

In short

  1. Amazon Bedrock gives many foundation models through one AWS API, with AWS login, billing and security.
  2. Choose a Region, copy the model ID from the catalog, and note that Anthropic models need a one-time form.
  3. The playground is the fastest way to compare models; new Free plan accounts earn USD 20 credit for trying it.
  4. In Python, boto3 and the Converse API call most models with the same code.
  5. botocore's Stubber tests your code with no account and no cost.
  6. Estimate token costs with real prices, set a budget alert, check quotas and always set maxTokens.

Start in the playground, test your code offline, then go live with small permissions and a budget alert. That order keeps both your app and your bill safe.

Previous chapter: Build Your First AI Agent in Python: Tools, Memory, Guardrails

Next chapter: RAG on AWS: Bedrock Knowledge Bases with S3 (Step by Step)


Ravindra Bagale, trainer: linkedin.com/in/ravindra-bagale. City Library, its members and the prices in the cost script are made up for learning. Bedrock facts were checked on the Amazon Bedrock user guide, the AWS Free Tier pages and the AWS News Blog on 19 October 2026. The Python output was produced on 19 October 2026 with boto3 1.43, using a stubbed (fake) reply. AI output changes every time, so your output will be similar, not the same.