Bedrock
/SKILLAWS Bedrock foundation models for generative AI. Use when invoking foundation models, building AI applications, creating embeddings, configuring model access, or implementing RAG patterns.
--- name: bedrock description: AWS Bedrock foundation models for generative AI. Use when invoking foundation models, building AI applications, creating embeddings, configuring model access, or implementing RAG patterns. lastupdated: "2026-01-07" docsource: https://docs.aws.amazon.com/bedrock/latest/userguide/ --- # AWS Bedrock Amazon Bedrock provides access to foundation models (FMs) from AI companies through a unified API. Build generative AI applications with text generation, embeddings, and image generation capabilities. ## Table of Contents - [Core Concepts](#core-concepts) - [Common Patterns](#common-patterns) - [CLI Reference](#cli-reference) - [Best Practices](#best-practices) - [Troubleshooting](#troubleshooting) - [References](#references) ## Core Concepts ### Foundation Models Pre-trained models available through Bedrock: - Claude (Anthropic): Text generation, analysis, coding - Titan (Amazon): Text, embeddings, image generation - Llama (Meta): Open-weight text generation - Mistral: Efficient text generation - Stable Diffusion (Stability AI): Image generation ### Model Access Models must be enabled in your account before use: - Request access in the Bedrock console - Some models require acceptance of EULAs - Access is region-specific ### Inference Types | Type | Use Case | Pricing | |------|----------|---------| | On-Demand | Variable workloads | Per token | | Provisioned Throughput | Consistent high-volume | Hourly commitment | | Batch Inference | Async large-scale | Discounted per token | ## Common Patterns ### Invoke Model (Text Generation) AWS CLI: ``bash # Invoke Claude aws bedrock-runtime invoke-model \ --model-id anthropic.claude-3-sonnet-20240229-v1:0 \ --content-type application/json \ --accept application/json \ --body '{ "anthropic_version": "bedrock-2023-05-31", "max_tokens": 1024, "messages": [ {"role": "user", "content": "Explain AWS Lambda in 3 sentences."} ] }' \ response.json cat response.json | jq -r '.content[0].text' ` **boto3:** `python import boto3 import json bedrock = boto3.client('bedrock-runtime') def invoke_claude(prompt, max_tokens=1024): response = bedrock.invoke_model( modelId='anthropic.claude-3-sonnet-20240229-v1:0', contentType='application/json', accept='application/json', body=json.dumps({ 'anthropic_version': 'bedrock-2023-05-31', 'max_tokens': max_tokens, 'messages': [ {'role': 'user', 'content': prompt} ] }) ) result = json.loads(response['body'].read()) return result['content'][0]['text'] # Usage response = invoke_claude('What is Amazon S3?') print(response) ` ### Streaming Response `python import boto3 import json bedrock = boto3.client('bedrock-runtime') def stream_claude(prompt): response = bedrock.invoke_model_with_response_stream( modelId='anthropic.claude-3-sonnet-20240229-v1:0', contentType='application/json', accept='application/json', body=json.dumps({ 'anthropic_version': 'bedrock-2023-05-31', 'max_tokens': 1024, 'messages': [ {'role': 'user', 'content': prompt} ] }) ) for event in response['body']: chunk = json.loads(event['chunk']['bytes']) if chunk['type'] == 'content_block_delta': yield chunk['delta'].get('text', '') # Usage for text in stream_claude('Write a haiku about cloud computing.'): print(text, end='', flush=True) ` ### Generate Embeddings ``python import boto3 import json bedrock = boto3.client('bedrock-runtime') def getembedding(text): response = bedrock.invokemodel( modelId='amazon.titan-embed-text-v2:0', contentType='application/json', accept='application/json', body=json.dumps({ 'inputText': text, 'dimensions': 1024, 'normalize': True }) ) result = json.loads(response['body'].read()) return result['embedding'] # Usage embedding = get_embedding('AWS Lambda is a serverless compute se