Ravindra BagaleCourses & study guides मराठी Track your progress

AWS Cloud

What Is Amazon Bedrock? Generative AI APIs on AWS Explained

Bedrock lets your app talk to foundation models (Claude, Llama, Titan and others) over AWS APIs. You do not train a giant GPU farm first. Perfect for chat, summarise and classify — with strict token cost discipline.

In this chapter

  • What Bedrock is
  • Model access and regions
  • Pricing mental model (tokens)
  • Guardrails and IAM
  • Cost warnings for student labs

1. Everyday example

A Swiggy support bot must turn a long complaint into a short category + reply draft. Building that model from scratch is years of work. Calling a foundation model with a good prompt can be a weekend.

Amazon Bedrock is a fully managed service to use foundation models via API (and tools like Knowledge Bases / Agents). Providers include Amazon and third parties, depending on region and account enablement.

One InvokeModel callYour appIAM roleBedrock APIap-south-1 or supported regionFoundation modelreturns text/embeddingYou storeresult in DynamoDB / S3
No endpoint cluster for you to patch for the base model.

2. Model access

Suppose a college help desk wants a two-sentence summary of a student’s ticket. The app sends a prompt, which is the instructions and example text supplied to the model. Bedrock exposes supported models through an API so the app can make that request. In a Converse request, identify the model, the list of messages and the role of each message. When a response arrives, read the returned message, the reason it stopped and the usage fields. These answer different questions: what it said, whether it finished normally, and how much input and output it processed.

Not every model is on in every account/region by default.

  1. Open the Bedrock Model catalog, choose the model and review its access requirements. Many models are enabled with the required permissions; some have provider or Marketplace prerequisites.
  2. Check the model is available in your region (Mumbai support grows over time — verify live).
  3. Call with AWS SDK (bedrock-runtime) using an IAM role that allows bedrock:InvokeModel on specific model ARNs.

3. Tokens and money

A token is a small piece of text counted by the model. It may be a whole word or part of one. A brief reply can still have a large input if the app sent a long ticket history. Try reading a sample with 300 input tokens and 30 output tokens. Shortening the expected reply only addresses the 30-token part. To address the 300, remove history the summariser does not need. For supported usage-based pricing, check the selected model’s input and output rates separately before estimating a batch of tickets.

You usually pay per input token and per output token. Long prompts + long answers + many test loops = surprise bills. Set budgets and alarms.

Lab discipline

Before any Bedrock lab: enable only one cheap model, set an AWS Budget alert (for example $5), keep max_tokens small, and never put Bedrock calls in an unbounded loop. If your org blocks Bedrock, skip the live call — reading this chapter is enough for the quiz.

4. Safety extras

Use fictional help-desk messages to check the behavior before using real tickets. Write one ordinary message and a second message that contains a value your selected guardrail should mask. Predict the summary and the expected guardrail action separately. A returned summary can sound certain while giving a wrong date, so compare factual details with the original text. Check permissions and data-handling rules around the model call too. A content filter addresses the text it evaluates, and the application remains responsible for how it handles the result.

  • Guardrails: filter topics/PII patterns before/after the model.
  • Least-privilege IAM on model IDs — not *.
  • Do not send secrets or customer passwords in prompts.
  • Log prompts carefully — they may contain personal data.

5. Bedrock vs SageMaker (again)

GoalPrefer
Chat, summarise, embed with a managed FMBedrock
Train a custom tabular/CV model on your labelled dataSageMaker
Fine-tune / customise some FMs on Bedrock where offeredBedrock customisation features
Full training loop + custom containersSageMaker

6. Interview angles

Q. Do you manage GPUs for base FM calls?

No — Bedrock hosts the model.

Q. Main API family?

bedrock-runtime InvokeModel / Converse APIs.

Q. How billed?

Primarily tokens (plus optional extras).

Q. Guardrails?

Managed filters around model I/O.

Q. SageMaker instead?

When you must train/host your own model deeply.

Try at home

  1. Read current Bedrock pricing page for one model — note input vs output rates.
  2. Draft an IAM policy that allows InvokeModel on a single model ARN only.

In short

  1. Bedrock = foundation model APIs on AWS.
  2. Enable model access; use bedrock-runtime.
  3. Tokens cost money — budgets and small max_tokens.
  4. Prefer Bedrock for generative APIs; SageMaker for custom training.

Practise this chapter

Interview questions and answers

A model-generated help desk summary names the wrong room. What do you verify?

Compare the summary with the source and identify the unsupported detail. Check model output and stop reason, then improve or reject the result using the app’s validation. A guardrail can evaluate configured content concerns, while verifying the actual room requires grounding in the original ticket or other trusted data.

Check your understanding

Choose an answer, then compare your reasoning with the explanation.

0 of 3 answered correctly
1. What does the usage field for output tokens count?

Answer and explanation

C. Model-generated text units in the output

Tokens are model-counted pieces of text. Input and output fields track different sides of the request.

2. A request uses 300 input tokens and 30 output tokens. Which design change reduces the larger count?

Answer and explanation

C. Remove unneeded context from the input

Shortening only the output limit affects output. Shorten unnecessary history or prompt context to reduce input usage.

3. Which test distinguishes accuracy from a content filter decision?

Answer and explanation

A. Compare one returned detail against a known source even when the filter permits the reply

Permitting or blocking content according to policy is separate from checking whether an output is faithful to the original.

Apply the concepts

  1. Write one accepted model response and one rejected response for the projector ticket. Use an explanation that names the exact evidence in the source.

    Check your result

    The accepted response preserves Monday, projector failure and Room 204. The rejected response introduces an unsupported room, date or cause. The explanation identifies exactly which detail needs correction.

Read a Bedrock inference request and check its result

Before you start

  • Use the fictional messages below and paper or a text editor. No credentials, model access or AWS account are required.
  • Keep the system instruction and user message separate in your sketch.
  1. Write the user message: 'The classroom projector failed on Monday. The trainer moved to Room 204.' Write an instruction to summarise in one sentence using only stated facts.

    Expected result: The user text contains two facts. The instruction limits format and forbids adding unstated details.

  2. Sketch a Converse request with a model ID placeholder, the instruction, one user message and an output length limit. Use a response containing 'On Monday the projector failed, so the class moved to Room 204.'

    Expected result: The request separates the selected model, system instruction, content and inference configuration. The response preserves the day, fault and room.

  3. Use dummy usage fields of 80 input tokens and 19 output tokens. If 10 identical-length calls run, calculate both totals separately. Now compare a shorter output of 9 tokens each.

    Expected result: The ten originals total 800 input and 190 output tokens. Shortening the output lowers that total to 90 output tokens while input remains 800.

  4. Add a second fictional input containing a value that a configured sensitive-information policy is meant to mask. Sketch the app handling the guardrail outcome, and separately compare a model response that mistakenly says Room 240.

    Expected result: You can distinguish a guardrail intervention from a factual error. The app needs its own checks to ensure the room matches the supplied ticket.

If the result differs

  • If you mixed input and output tokens, read the two usage fields separately before multiplying by the call count.
  • When the response hallucinates a new detail, trace it back to the exact source sentence and decide how to reject or correct it.

Finish and clean up

  • Remove temporary copies of the dummy messages after your review. No model invocation or cloud resources were created.

Practice Tasks

Practice checks run in your browser. They check the answer for this exercise; they do not create resources or connect to your AWS account.

About this scenario

Solapur Chaddar House is a home textiles business in Solapur. Vikas Kamble looks after its IT and cloud work. They count money in INR and run their AWS resources in the ap-south-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 10

Easy List Bedrock models

See which foundation models are offered in your Region.

List the foundation models available in Amazon Bedrock.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy List SageMaker endpoints

Endpoints cost money every hour; list them to find forgotten ones.

List SageMaker endpoints.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy How many addresses in a /16?

Picking a VPC size needs this count.

Solapur Chaddar House plans the VPC 10.86.0.0/16. How many IP addresses does it hold in total?

  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Port for SSH

Security group rules need the right port.

Which TCP port must the security group open for SSH?

  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Show where you are

Before you copy or delete anything, you must know which folder you are in.

Vikas Kamble logged in to the Solapur Chaddar House server and is not sure which folder the terminal is in. Print the current folder path.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Read-only access to one bucket

Least privilege: give only the actions and the bucket the job needs.

Write an identity policy that lets the user read objects (s3:GetObject) only in bucket solapurchaddar-data.

  1. Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
  2. In each statement write Effect, Action and Resource.
  3. Give only what the task needs (least privilege).
  4. Use double quotes and commas correctly. Click Check answer.

Medium Detect labels in an image

Rekognition names objects in a photo, e.g. to tag product images.

Detect labels in s3://solapurchaddar-media/shop/p1.jpg (Bucket=solapurchaddar-media, Name=shop/p1.jpg), max 10 labels.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Allow one Bedrock model

Limit apps to the approved model so costs stay predictable.

Allow bedrock:InvokeModel on arn:aws:bedrock:ap-south-1::foundation-model/amazon.nova-lite-v1:0 only.

  1. Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
  2. In each statement write Effect, Action and Resource.
  3. Give only what the task needs (least privilege).
  4. Use double quotes and commas correctly. Click Check answer.

Medium Usable IPs in an AWS /24 subnet

AWS keeps 5 addresses in every subnet.

How many addresses can Solapur Chaddar House use for servers in subnet 10.86.1.0/24 on AWS?

  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Hard Ask a model a question

Converse is one API shape for many models.

Call converse on model amazon.nova-lite-v1:0 with the messages in msgs.json.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Revision, comparison and interview cards

Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.

Revision card: What is Amazon Bedrock?. Support bots need summarise and reply drafts in a weekend — not years to train a giant model. Amazon Bedrock lets apps call foundation models (Claude, Llama, Titan and more) through AWS APIs and IAM. Enable model access in console → call bedrock-runtime with an IAM role that allows InvokeModel on specific model IDs. A short prompt returns a completion; you store the result in DynamoDB or S3 if needed.
Revision card: What is Amazon Bedrock? · Download PNG · Open card page
Revision card: Tokens and cost discipline. Long prompts, long answers, and unbounded test loops create surprise bills. You usually pay per input token and per output token. Keep max_tokens small in labs; set AWS Budgets. Enable one cheap model, budget alert (e.g. $5), never put Bedrock in an infinite loop. Ten short test calls stay cheap; a loop of 100k-token dumps does not.
Revision card: Tokens and cost discipline · Download PNG · Open card page
Revision card: Guardrails and IAM. Prompts can leak PII; wildcard model access is too broad. Bedrock Guardrails filter topics/PII patterns. IAM should allow InvokeModel only on the model ARNs you need. Attach a policy with bedrock:InvokeModel on one model ARN; add a Guardrail in console for the app use case. A denied model ID fails closed; a Guardrail blocks a disallowed topic before it reaches users.
Revision card: Guardrails and IAM · Download PNG · Open card page
Comparison: Bedrock token pricing vs SageMaker instance hours. Bedrock token pricing: Pay per input/output tokens of each call. SageMaker instance hours: Pay for notebook/training/endpoint instance time.
Comparison: Bedrock token pricing vs SageMaker instance hours · Download PNG · Open card page
Interview card: Bedrock or SageMaker for a chatbot?. If a managed foundation model API is enough, Bedrock. If you must train a custom model on your labels, SageMaker. Chat/summarise is the classic Bedrock fit. InvokeModel on Claude/Llama-class models via Bedrock; keep tokens bounded.
Interview card: Bedrock or SageMaker for a chatbot? · Download PNG · Open card page
Interview card: Why can InvokeModel fail with access errors?. Model access may be off in the account/region, or IAM lacks bedrock:InvokeModel on that model ARN. Regions differ; always verify model availability where you call. Console Model access enable + IAM Allow InvokeModel on specific model ID.
Interview card: Why can InvokeModel fail with access errors? · Download PNG · Open card page

More cards: Ravi Sir's Cards.