Course menuDVA-C03

Exams / DVA-C03 / Study guide / Calling Amazon Bedrock from application code

Calling Amazon Bedrock from application code: DVA-C03 study notes and practice questions

What to know about Calling Amazon Bedrock from application code for the DVA-C03 exam, from the Development with AWS Services domain (30% of the exam guide), then 1 free question to test it. Part of the DVA-C03 study guide.

Last verified against current AWS documentation ·How we write our questions

What to know for the exam

Bedrock questions describe an application that calls a model, and ask which API, option or retry pattern meets a requirement. You are not expected to choose a model or write prompts. Focus on the call, the streaming, the limits and the access controls.

Choosing the API

  • Converse and ConverseStream use one request shape for every Bedrock model that supports messages, and return one normalized response with the output, stop reason and token usage. Use them by default, so switching models needs little code change.
  • InvokeModel and InvokeModelWithResponseStream send the model’s own request body. Use them when a model needs a feature the Converse format doesn’t expose. The body is a JSON string or bytes in the model’s own format, not a language-native object, and the response body is a stream that your code reads and decodes before parsing.
  • Streaming returns text as it is generated, which suits chat interfaces. Streaming support varies by model.
  • Prompt caching stores a long, repeated prompt prefix, such as a fixed system prompt, so later requests read it at a lower rate. Place the cache checkpoint after the static content.
  • Step Functions has an optimized Bedrock InvokeModel task, so a workflow calls a model without a Lambda function. Its Body field takes up to 256 KiB; for larger requests, the Input field points to an S3 object instead.

Tool use

  • You describe tools in the request (toolConfig in Converse). The model responds with a toolUse block and a stop reason of tool_use, naming a tool and its input.
  • Your code runs the tool and sends a toolResult block with the same toolUseId in the next user message. The loop continues until the model returns a final answer.
  • Your application, not the model, runs the tool, so check permissions in your code.

Throttling and retries

  • When a quota is exceeded, Bedrock returns ThrottlingException. Retry with exponential backoff and jitter. The AWS SDKs retry throttling errors automatically, and you can configure more attempts.
  • For steady, predictable load, buy provisioned throughput. For spiky load, on-demand quotas can be the bottleneck.
  • Cross-Region inference profiles route requests across Regions to absorb spikes. The call uses the profile’s ID, often with a us. or eu. prefix.
  • Application inference profiles add tags so costs can be tracked per team or feature.

Batch inference

  • For large jobs where answers are not needed right away, use batch inference. You put input in Amazon S3 and read the output from S3 when the job finishes. It costs less than real-time calls.

Calling an AgentCore Runtime agent

  • Amazon Bedrock AgentCore Runtime hosts an agent. Your application calls the agent’s runtime endpoint with the AWS SDK, (InvokeAgentRuntime), using IAM credentials or the configured inbound authentication. Pass a unique runtimeSessionId (at least 33 characters) per conversation: each session runs in its own microVM, and reusing the ID keeps the conversation’s context. A session stops after 15 minutes idle or 8 hours by default, and its in-memory state is lost, so use AgentCore Memory for history that must outlast the session.

How to choose

Scenario wording Answer
Same code must work across several text models Converse
Model-specific feature not in the common format InvokeModel
Chat response shown as it is generated ConverseStream or streaming InvokeModel
Model asks to call a function in your app Tool use
Throttling errors during peaks Backoff and retries, cross-Region profile, or provisioned throughput
Thousands of documents, overnight, cheap Batch inference with S3 input and output
Application must call a hosted agent AgentCore Runtime invocation
Same long system prompt on every request Prompt caching
Workflow step calls a model with no Lambda function Step Functions optimized Bedrock task

Common traps

  • Batch inference for a live user request.
  • Ignoring throttling instead of retrying with backoff.
  • Giving the application’s code broad bedrock:* rights. Grant only the invoke actions it needs.
  • Forgetting that tool execution happens in your code.
  • Retrying throttled calls with no delay, or with a fixed sleep that sends retries together.
  • Reusing one session ID for every user of an AgentCore agent.

Try the 1 practice question

A retail company's support app sends customer chat messages to a foundation model on Amazon Bedrock. The code calls InvokeModel, and each model family needs its own request body and its own response parser.

The team wants to test two other Bedrock models next quarter. The code must keep one message format for conversation turns, and it must read the reply text and token counts the same way for every model.

Which change meets these requirements with the LEAST code change?

Choose one answer.

  1. A. Keep InvokeModel, and add a separate request builder and response parser for each model family, chosen by the model ID at run time in the code.
  2. B. Change the calls to the Converse API, which uses one message format and one response structure for every model that supports messages.
  3. C. Call InvokeModelWithResponseStream instead, and keep the existing model-specific parsing code for each streamed chunk.
  4. D. Convert every prompt to plain text and send it with the InvokeModel body that the first model family uses for all models.
Show the answer and explanation

Answer: B

  • A. Wrong: This works, but each new model needs another builder and parser, so the code keeps growing. It does not give the team one message format with the least change.
  • B. Right: Correct. The Converse API gives one request format for every Bedrock model that supports messages, and it returns output, stop reason and usage in a standard shape. Trying another model usually means changing the model ID. Learn more: Carry out a conversation with the Converse API (opens in a new tab)
  • C. Wrong: Streaming changes how the reply arrives, not the request body. The chunks still differ by model, so the parsing code stays model-specific.
  • D. Wrong: A body built for one model family is not accepted by others, because each family expects its own request and response shape. Plain text alone does not give the team a single response structure.

Explanation

The Converse API gives one request shape across Bedrock models that support messages, and one normalized response with output, stop reason and usage. InvokeModel bodies are model-specific, so every new model adds parsing code. Moving the calls to Converse is the change that needs the least code.

Study

Want more on Calling Amazon Bedrock from application code? The 5 full-length practice sets have 8 more Calling Amazon Bedrock from application code questions, 390 in all, none of them in the free exam. One payment of $14.99, no subscription. See the practice sets

Study Calling Amazon Bedrock from application code

More Development with AWS Services topics