bedrock by itsmostafa/aws-agent-skills
npx skills add https://github.com/itsmostafa/aws-agent-skills --skill bedrockAmazon Bedrock 通过统一的 API 提供对 AI 公司基础模型(FMs)的访问。利用文本生成、嵌入和图像生成功能构建生成式 AI 应用程序。
通过 Bedrock 可用的预训练模型:
模型必须在您的账户中启用后才能使用:
| 类型 | 使用场景 | 定价 |
|---|---|---|
| 按需 | 可变工作负载 | 按令牌计费 |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 预置吞吐量 |
| 持续高容量 |
| 每小时承诺 |
| 批量推理 | 异步大规模处理 | 折扣的每令牌计费 |
AWS CLI:
# 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:
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)
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)
import boto3
import json
bedrock = boto3.client('bedrock-runtime')
def get_embedding(text):
response = bedrock.invoke_model(
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 service.')
print(f'Embedding dimension: {len(embedding)}')
import boto3
import json
bedrock = boto3.client('bedrock-runtime')
class Conversation:
def __init__(self, system_prompt=None):
self.messages = []
self.system = system_prompt
def chat(self, user_message):
self.messages.append({
'role': 'user',
'content': user_message
})
body = {
'anthropic_version': 'bedrock-2023-05-31',
'max_tokens': 1024,
'messages': self.messages
}
if self.system:
body['system'] = self.system
response = bedrock.invoke_model(
modelId='anthropic.claude-3-sonnet-20240229-v1:0',
contentType='application/json',
accept='application/json',
body=json.dumps(body)
)
result = json.loads(response['body'].read())
assistant_message = result['content'][0]['text']
self.messages.append({
'role': 'assistant',
'content': assistant_message
})
return assistant_message
# Usage
conv = Conversation(system_prompt='You are an AWS solutions architect.')
print(conv.chat('What database should I use for a chat application?'))
print(conv.chat('What about for time-series data?'))
# List all foundation models
aws bedrock list-foundation-models \
--query 'modelSummaries[*].[modelId,modelName,providerName]' \
--output table
# Filter by provider
aws bedrock list-foundation-models \
--by-provider anthropic \
--query 'modelSummaries[*].modelId'
# Get model details
aws bedrock get-foundation-model \
--model-identifier anthropic.claude-3-sonnet-20240229-v1:0
# List model access status
aws bedrock list-foundation-model-agreement-offers \
--model-id anthropic.claude-3-sonnet-20240229-v1:0
| 命令 | 描述 |
|---|---|
aws bedrock list-foundation-models | 列出可用模型 |
aws bedrock get-foundation-model | 获取模型详情 |
aws bedrock list-custom-models | 列出微调模型 |
aws bedrock create-model-customization-job | 开始微调 |
aws bedrock list-provisioned-model-throughputs | 列出预置容量 |
| 命令 | 描述 |
|---|---|
aws bedrock-runtime invoke-model | 同步调用模型 |
aws bedrock-runtime invoke-model-with-response-stream | 流式调用 |
aws bedrock-runtime converse | 多轮对话 API |
aws bedrock-runtime converse-stream | 流式对话 |
| 命令 | 描述 |
|---|---|
aws bedrock-agent-runtime invoke-agent | 调用 Bedrock 代理 |
aws bedrock-agent-runtime retrieve | 查询知识库 |
aws bedrock-agent-runtime retrieve-and-generate | RAG 查询 |
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream"
],
"Resource": [
"arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0",
"arn:aws:bedrock:us-east-1::foundation-model/amazon.titan-embed-text-v2:0"
]
}
]
}
原因:
bedrock:InvokeModel调试:
# Check model access status
aws bedrock list-foundation-models \
--query 'modelSummaries[?modelId==`anthropic.claude-3-sonnet-20240229-v1:0`]'
# Test IAM permissions
aws iam simulate-principal-policy \
--policy-source-arn arn:aws:iam::123456789012:role/my-role \
--action-names bedrock:InvokeModel \
--resource-arns "arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0"
原因: 模型仍在预置中或暂时不可用。
解决方案: 使用指数退避实现重试:
import time
from botocore.exceptions import ClientError
def invoke_with_retry(bedrock, body, max_retries=3):
for attempt in range(max_retries):
try:
return bedrock.invoke_model(
modelId='anthropic.claude-3-sonnet-20240229-v1:0',
body=json.dumps(body)
)
except ClientError as e:
if e.response['Error']['Code'] == 'ModelNotReadyException':
time.sleep(2 ** attempt)
else:
raise
raise Exception('Max retries exceeded')
原因:
解决方案:
常见问题:
调试:
# Check model-specific requirements
aws bedrock get-foundation-model \
--model-identifier anthropic.claude-3-sonnet-20240229-v1:0 \
--query 'modelDetails.inferenceTypesSupported'
每周安装量
82
代码仓库
GitHub 星标数
1.0K
首次出现
2026年1月24日
安全审计
安装于
opencode73
codex69
gemini-cli66
cursor62
github-copilot57
claude-code57
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.
Pre-trained models available through Bedrock:
Models must be enabled in your account before use:
| 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 |
AWS CLI:
# 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:
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)
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)
import boto3
import json
bedrock = boto3.client('bedrock-runtime')
def get_embedding(text):
response = bedrock.invoke_model(
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 service.')
print(f'Embedding dimension: {len(embedding)}')
import boto3
import json
bedrock = boto3.client('bedrock-runtime')
class Conversation:
def __init__(self, system_prompt=None):
self.messages = []
self.system = system_prompt
def chat(self, user_message):
self.messages.append({
'role': 'user',
'content': user_message
})
body = {
'anthropic_version': 'bedrock-2023-05-31',
'max_tokens': 1024,
'messages': self.messages
}
if self.system:
body['system'] = self.system
response = bedrock.invoke_model(
modelId='anthropic.claude-3-sonnet-20240229-v1:0',
contentType='application/json',
accept='application/json',
body=json.dumps(body)
)
result = json.loads(response['body'].read())
assistant_message = result['content'][0]['text']
self.messages.append({
'role': 'assistant',
'content': assistant_message
})
return assistant_message
# Usage
conv = Conversation(system_prompt='You are an AWS solutions architect.')
print(conv.chat('What database should I use for a chat application?'))
print(conv.chat('What about for time-series data?'))
# List all foundation models
aws bedrock list-foundation-models \
--query 'modelSummaries[*].[modelId,modelName,providerName]' \
--output table
# Filter by provider
aws bedrock list-foundation-models \
--by-provider anthropic \
--query 'modelSummaries[*].modelId'
# Get model details
aws bedrock get-foundation-model \
--model-identifier anthropic.claude-3-sonnet-20240229-v1:0
# List model access status
aws bedrock list-foundation-model-agreement-offers \
--model-id anthropic.claude-3-sonnet-20240229-v1:0
| Command | Description |
|---|---|
aws bedrock list-foundation-models | List available models |
aws bedrock get-foundation-model | Get model details |
aws bedrock list-custom-models | List fine-tuned models |
aws bedrock create-model-customization-job | Start fine-tuning |
aws bedrock list-provisioned-model-throughputs | List provisioned capacity |
| Command | Description |
|---|---|
aws bedrock-runtime invoke-model | Invoke model synchronously |
aws bedrock-runtime invoke-model-with-response-stream | Invoke with streaming |
aws bedrock-runtime converse | Multi-turn conversation API |
aws bedrock-runtime converse-stream | Streaming conversation |
| Command | Description |
|---|---|
aws bedrock-agent-runtime invoke-agent | Invoke a Bedrock agent |
aws bedrock-agent-runtime retrieve | Query knowledge base |
aws bedrock-agent-runtime retrieve-and-generate | RAG query |
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream"
],
"Resource": [
"arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0",
"arn:aws:bedrock:us-east-1::foundation-model/amazon.titan-embed-text-v2:0"
]
}
]
}
Causes:
bedrock:InvokeModelDebug:
# Check model access status
aws bedrock list-foundation-models \
--query 'modelSummaries[?modelId==`anthropic.claude-3-sonnet-20240229-v1:0`]'
# Test IAM permissions
aws iam simulate-principal-policy \
--policy-source-arn arn:aws:iam::123456789012:role/my-role \
--action-names bedrock:InvokeModel \
--resource-arns "arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0"
Cause: Model is still being provisioned or temporarily unavailable.
Solution: Implement retry with exponential backoff:
import time
from botocore.exceptions import ClientError
def invoke_with_retry(bedrock, body, max_retries=3):
for attempt in range(max_retries):
try:
return bedrock.invoke_model(
modelId='anthropic.claude-3-sonnet-20240229-v1:0',
body=json.dumps(body)
)
except ClientError as e:
if e.response['Error']['Code'] == 'ModelNotReadyException':
time.sleep(2 ** attempt)
else:
raise
raise Exception('Max retries exceeded')
Causes:
Solutions:
Common issues:
Debug:
# Check model-specific requirements
aws bedrock get-foundation-model \
--model-identifier anthropic.claude-3-sonnet-20240229-v1:0 \
--query 'modelDetails.inferenceTypesSupported'
Weekly Installs
82
Repository
GitHub Stars
1.0K
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode73
codex69
gemini-cli66
cursor62
github-copilot57
claude-code57
Azure 配额管理指南:服务限制、容量验证与配额增加方法
116,900 周安装