Bedrock Runtime: InvokeModel, exceeded maximum number of attempts, 3, https resp...
错误信息
status_code=503, InvokeModel: operation error Bedrock Runtime: InvokeModel, exceeded maximum number of attempts, 3, https response error StatusCode: 503, RequestID: 5d75279c-23af-4b1e-a1a9-cc4ed46e1185, ServiceUnavailableException: Bedrock is unable to process your request.
AI 解决方案
🔍 错误分析
1. 🌐 错误翻译
原文:status_code=503, InvokeModel: operation error Bedrock Runtime: InvokeModel, exceeded maximum number of attempts, 3, https response error StatusCode: 503, RequestID: 5d75279c-23af-4b1e-a1a9-cc4ed46e1185, ServiceUnavailableException: Bedrock is unable to process your request.
译文:状态码=503,调用模型:操作错误 Bedrock Runtime:调用模型,超过最大尝试次数,3次,https响应错误 状态码:503,请求ID:5d75279c-23af-4b1e-a1a9-cc4ed46e1185,服务不可用异常:Bedrock 无法处理您的请求。
2. 🎯 原因分析
3. 💡 解决方案
``
代码语言
// 增加重试次数和重试间隔,实现指数退避策略
const MAX_RETRIES = 10;
const BASE_DELAY = 1000; // 1秒async function invokeBedrockWithRetry(request) {
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
try {
const response = await bedrockRuntimeClient.send(request);
return response;
} catch (error) {
if (error.$metadata && error.$metadata.httpStatusCode === 503) {
if (attempt === MAX_RETRIES) throw error;
// 指数退避等待
const delay = BASE_DELAY * Math.pow(2, attempt - 1);
console.log(
Bedrock 503, retry ${attempt}/${MAX_RETRIES} in ${delay}ms...);
await new Promise(resolve => setTimeout(resolve, delay));
} else {
throw error;
}
}
}
}// 使用示例
await invokeBedrockWithRetry(modelRequest);
``