Bedrock Runtime: InvokeModel, exceeded maximum number of attempts, 3, https resp...

2026年07月12日 02:31 19.51 秒 success

错误信息

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. 🎯 原因分析


  • 根本原因:AWS Bedrock 服务当前不可用或过载,导致无法处理请求

  • 具体位置:在调用 Bedrock 模型接口时发生

  • 上下文:已经重试了3次,均返回503服务不可用错误,表明是服务端问题而非客户端代码错误
  • 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);
    ``

    4. 🛡️ 预防措施


  • 重试策略:实现指数退避重试机制,自动处理临时服务不可用问题

  • 监控告警:集成 CloudWatch 监控,当503错误率超过阈值时自动告警

  • 使用 AWS 服务健康仪表板:在调用前先检查 Bedrock 服务健康状态

  • 降级处理:准备备用方案,当 Bedrock 不可用时切换到备用模型或缓存响应