Amazon Bedrock 入门
Nikhil Rangarajan
Data Scientist




注意:本课程中已预置 Access Key 和 Secret Key。
'us-east-1')
# 非生产安全做法,仅用于教学 AWS_REGION = 'us-east-1'AWS_ACCESS_KEY = 'your-access-key'AWS_SECRET_KEY = 'your-secret-key'
'bedrock-runtime' 进行模型推理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)
'bedrock'
# 验证 Bedrock 客户端配置 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.
get_foundation_model() 获取模型详情
amazon.nova-2-lite-v1:0、anthropic.claude-sonnet-4-5-20250929-v1:0
response = bedrock_client.get_foundation_model
(modelIdentifier='anthropic.claude-sonnet-4-5-20250929-v1:0')
print(response['modelDetails'])
{'modelArn': 'arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-sonnet-4-5...',
'modelId': 'anthropic.claude-sonnet-4-5-20250929-v1:0',
'modelName': 'Claude Sonnet 4.5',
'providerName': 'Anthropic',
'inputModalities': ['TEXT', 'IMAGE'],
'outputModalities': ['TEXT'],
'responseStreamingSupported': True,
'customizationsSupported': [],
'inferenceTypesSupported': ['INFERENCE_PROFILE'],
'modelLifecycle': {'status': 'ACTIVE', 'startOfLifeTime': ...}
Amazon Bedrock 入门