AWS Generative AI Developer Professional Prep
Amazon Bedrock Implementation
Bedrock's Core Architecture
Amazon Bedrock acts as a unified gateway to a range of foundation models (FMs) from various providers. Instead of building separate integrations for each model provider, you interact with a single, consistent API. This simplifies development and allows you to swap models with minimal code changes.
When you send a request, Bedrock routes it to the specified model, manages the underlying infrastructure, and returns the response. This serverless approach means you don't manage any servers; you only pay for what you use during inference. Security and compliance are also streamlined. Bedrock operates within your AWS environment, allowing you to use familiar tools like AWS Identity and Access Management (IAM) for permissions and AWS Key Management Service (KMS) for data encryption.
Invoking Models
Bedrock provides two primary API actions for running inference: InvokeModel and Converse.
InvokeModelis the foundational method. It gives you direct access to a specific model's native inference parameters, offering maximum control. The request body and response format are unique to each model provider.
# Example using InvokeModel with Anthropic Claude
import boto3
import json
bedrock_runtime = boto3.client(service_name='bedrock-runtime')
body = json.dumps({
"prompt": "\n\nHuman: What is the capital of France?\n\nAssistant:",
"max_tokens_to_sample": 300,
"temperature": 0.7,
"top_p": 1,
})
response = bedrock_runtime.invoke_model(
body=body,
modelId='anthropic.claude-v2',
accept='application/json',
contentType='application/json'
)
Notice the body is a JSON string tailored specifically for Claude. Parameters like max_tokens_to_sample and the Human: / Assistant: prompt format are specific to Anthropic's models. If you were to switch to a model from Meta, you'd need to change this structure entirely.
The Converse API is a more recent, higher-level abstraction. It provides a standardized input and output format across different models and providers. This is ideal for building multi-modal and conversational applications, as it simplifies model switching. You lose some of the fine-grained control over model-specific parameters but gain significant development speed.
Performance and Quotas
By default, Bedrock models operate in an on-demand, multi-tenant environment. This is cost-effective for variable or unpredictable workloads. However, for applications requiring consistent latency and high throughput, this shared model can introduce variability. For these use cases, Bedrock offers Provisioned Throughput., annotations: [{"highlightText": "Provisioned Throughput", "annotationText": "## Reserved Power\n\nThink of Provisioned Throughput like a reserved lane on a motorway.\n\nInstead of competing with other traffic (multi-tenant environment), you pay for a dedicated amount of processing capacity for a specific model.\n\nThis is measured in 'Model Units' (MUs). One MU generally corresponds to a certain throughput level, which varies by model. It's a commitment-based pricing model (1-month or 6-month terms) that guarantees performance for your critical applications."}]
You purchase a set number of 'Model Units' for a specific model version, which guarantees a certain level of throughput. This transforms performance from a variable to a fixed capacity, making it predictable for production systems.
All AWS services have limits, and Bedrock is no exception. These exist to protect both you and AWS from unintended usage spikes. You'll encounter quotas on things like the number of concurrent InvokeModel requests per second (TPS) and the total number of tokens processed per minute (TPM). These quotas are region-specific and vary by model.
| Model Family | Typical Use Case | Throughput (On-Demand) | Latency (On-Demand) |
|---|---|---|---|
| Amazon Titan | General purpose, text generation, summarisation | Balanced | Low |
| Anthropic Claude | Complex reasoning, detailed conversations | Moderate | Moderate-High |
| Meta Llama | Open source, fine-tuning flexibility | High | Low-Moderate |
| Cohere Command | Enterprise-grade RAG, multilingual | High | Low |
| Stability AI | Image generation (Stable Diffusion) | N/A (Image-specific) | Variable |
The table above gives a high-level comparison. Choosing the right model involves balancing these performance characteristics with cost and specific feature support. For an exam, it's crucial to know which models are best suited for tasks like Retrieval-Augmented Generation (RAG) versus creative text generation.
Shared Responsibility
Like all AWS services, Bedrock operates under a .. AWS is responsible for the 'security of the cloud', which includes protecting the infrastructure that runs all AWS services. This covers the physical security of data centres, the hardware, and the software that powers the Bedrock service itself. AWS also manages the security and patching of the underlying foundation models.
Your responsibility is 'security in the cloud'. This means you are responsible for:
- IAM Permissions: Configuring which users and roles can access which models.
- Data Encryption: Using KMS keys to encrypt the data you send to models and the custom models you create.
- VPC Endpoints: Securing network traffic by keeping it within your Virtual Private Cloud (VPC) and off the public internet.
- Logging and Monitoring: Using services like CloudTrail and CloudWatch to monitor API calls and model usage for security and operational insights.
Amazon Bedrock is a fully managed service that provides a unified API to access a wide range of high-performing foundation models (FMs) from leading AI companies like Anthropic, Cohere, Meta, Mistral AI, AI21 Labs, Stability AI, and Amazon.
Before you can use any model, you must explicitly request access to it in the Bedrock console. This is a deliberate security step. By default, no models are enabled. This prevents accidental usage and ensures you only enable the models you have reviewed and approved for your use case.
Time to check your understanding of these core implementation details.
A developer is building a conversational application and wants the flexibility to easily switch between different foundation models (e.g., from Anthropic to Meta) with minimal code changes. Which Bedrock API action is best suited for this requirement?
An enterprise application requires guaranteed, consistent low latency and high throughput for its connection to a specific foundation model on Bedrock. The workload is predictable. Which Bedrock feature is designed to meet these performance requirements?
Mastering these architectural and operational concepts is fundamental for deploying robust, scalable, and secure generative AI applications on AWS.
