Module 1 of 11 · AWS Bedrock — Build with Foundation Models · Intermediate

Introduction to AWS Bedrock

Duration: 45 min

AWS Bedrock is a fully managed service that provides access to foundation models (FMs) via a simple API. Instead of managing infrastructure or fine-tuning models yourself, you invoke pre-trained models from leading AI companies like Anthropic, Meta, Mistral, and Stability AI. This module covers what Bedrock is, the models available, pricing, and real-world use cases.

What is AWS Bedrock?

Bedrock abstracts away the complexity of deploying and managing foundation models. You get:

Foundation Models Explained

A foundation model is a large neural network trained on massive amounts of text, code, or images. They're "foundational" because they can be adapted to many downstream tasks without retraining from scratch.

Key characteristics:

Bedrock Pricing Model

Bedrock uses on-demand pricing (pay per token) or provisioned throughput (reserved capacity):

{
  "on_demand": {
    "claude_3_sonnet": {
      "input_tokens": "$0.003 per 1K tokens",
      "output_tokens": "$0.015 per 1K tokens"
    },
    "llama_2_70b": {
      "input_tokens": "$0.00195 per 1K tokens",
      "output_tokens": "$0.00256 per 1K tokens"
    }
  },
  "provisioned_throughput": {
    "description": "Reserve capacity for predictable workloads",
    "commitment": "1 or 6 month terms",
    "discount": "Up to 40% savings vs on-demand"
  }
}

Common Use Cases

1. Customer Support Chatbots

2. Content Generation

3. Data Analysis & Insights

4. Code Assistance

5. Retrieval-Augmented Generation (RAG)

Getting Started with Bedrock

Prerequisites

# Install AWS CLI v2
curl "https://awscli.amazonaws.com/awscli-exe-macos.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

# Install boto3
pip install boto3

# Configure AWS credentials
aws configure

Enable Model Access

Models in Bedrock are disabled by default. Enable them in the AWS Console:

# List available models
aws bedrock list-foundation-models --region us-east-1

# Or enable via console: Bedrock > Model access > Request access

First API Call

import boto3

client = boto3.client('bedrock-runtime', region_name='us-east-1')

response = client.invoke_model(
    modelId='anthropic.claude-3-sonnet-20240229-v1:0',
    body=json.dumps({
        "anthropic_version": "bedrock-2023-06-01",
        "max_tokens": 1024,
        "messages": [
            {
                "role": "user",
                "content": "What is AWS Bedrock?"
            }
        ]
    })
)

result = json.loads(response['body'].read())
print(result['content'][0]['text'])

Bedrock vs Alternatives

Feature Bedrock OpenAI API Self-hosted
Model choice Multiple providers GPT only Any model
Data privacy Stays in AWS Sent to OpenAI Full control
Setup time Minutes Minutes Hours/days
Cost predictability On-demand or reserved On-demand only Infrastructure costs
Compliance AWS compliance Limited Full control

❓ What is the primary advantage of AWS Bedrock?

❓ Which pricing model offers up to 40% savings?

❓ What must you do before using a model in Bedrock?

❓ Which use case is NOT mentioned as a Bedrock strength?

Continue interactively → Next →

Related Courses