Accessing Amazon Bedrock

Introduction to Amazon Bedrock

Nikhil Rangarajan

Data Scientist

Meet your instructor!

  • Machine Learning Engineer
  • Cloud Technology (AWS, Azure)
  • Data, Cloud, and Computer Engineering

The profile photo of the instructor

Introduction to Amazon Bedrock

What is Amazon Bedrock?

  • Amazon's service

The AWS and Amazon Bedrock logos

Introduction to Amazon Bedrock

What is Amazon Bedrock?

  • Amazon's service
  • AI models called via API
    • API: a messenger between software systems
  • Bedrock provides access to models from companies such as Anthropic, Meta, etc.
  • No model setup or training needed - pay as you go

The AWS and Amazon Bedrock logos, and a diagram of an API.

Introduction to Amazon Bedrock

Foundation models in Generative AI

  • Pre-trained models
  • Serve as a base for multiple AI tasks
  • Generate text, code, images based on prompts
    • Text/Chat: Claude, Jurassic
    • Image: Stable Diffusion
    • Embedding: Titan

 

A diagram showing a Foundation Model at the center with four outward arrows connecting to different capabilities: Text/Chat, Embeddings, Code, and Images.

Introduction to Amazon Bedrock

Understanding access to Amazon Bedrock

Note: Throughout this course, Access Key and Secret Key have been pre-loaded.

 

  • Enable Bedrock Access in AWS:
    • Create an IAM User in AWS Console
    • Add Amazon Bedrock Full Access
    • Get your access credentials:
      • Access Key
      • Secret Key
      • Region (e.g., 'us-east-1')

A flowchart showing three steps to enable Amazon Bedrock access in AWS. Step 1: Create IAM User, Step 2: Add Bedrock Access, Step 3: Get Credentials.

Introduction to Amazon Bedrock

Setting up Bedrock runtime access

  • Configure AWS credentials in your environment
# Not secure for production, only for teaching purposes
AWS_REGION = 'us-east-1'

AWS_ACCESS_KEY = 'your-access-key'
AWS_SECRET_KEY = 'your-secret-key'
  • Initialize Bedrock client
  • Use 'bedrock-runtime' for model inference
    import boto3 
    bedrock = boto3.client('bedrock-runtime', # use -runtime
      region_name=AWS_REGION,
      aws_access_key_id=AWS_ACCESS_KEY,
      aws_secret_access_key=AWS_SECRET_KEY)
    
Introduction to Amazon Bedrock

Setting up Bedrock access

  • Check client initialization status
  • Use 'bedrock' for operational requests

 

# Verify Bedrock client configuration
import boto3
bedrock_client = boto3.client('bedrock', region_name='us-east-1')

models = bedrock_client.list_foundation_models() print(f"Connected successfully! Found {len(models['modelSummaries'])} available models.")
Connected successfully!  Found 13 available models.
Introduction to Amazon Bedrock

Information on foundation models

  • Use get_foundation_model() to retrieve model details

 

  • Need a ModelID, unique identifier
    • Example: amazon.nova-micro-v1:0, anthropic.claude-3-5-sonnet-v2:0

 

response = bedrock_client.get_foundation_model
    (modelIdentifier='anthropic.claude-3-5-sonnet-v2:0')
print(response)
Introduction to Amazon Bedrock

Information on foundation models

{
 'modelDetails': {

'modelName': 'anthropic.claude-3-5-sonnet-v2:0', 'modelId': 'anthropic.claude-3-5-sonnet-v2:0', 'providerName': 'Anthropic', 'modelArn': 'arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-5-sonnet',
'inputModalities': ['TEXT'], 'outputModalities': ['TEXT'], 'responseStreamingSupported': True, 'inferenceTypesSupported': ['ON_DEMAND'], 'modelLifecycle': {'status': 'ACTIVE'}
} }
Introduction to Amazon Bedrock

Let's practice!

Introduction to Amazon Bedrock

Preparing Video For Download...