Bedrock Runtime: InvokeModel, https response error StatusCode: 403, RequestID: 2...
🚨 错误信息
InvokeModel: operation error Bedrock Runtime: InvokeModel, https response error StatusCode: 403, RequestID: 2ffe2fd6-d004-4f25-a7ea-569ad5f0e3cf, api error UnrecognizedClientException: The security token included in the request is invalid.(request id: 2026022816424477770901E41s5rs7) (request id: 202602280842434589434901JbbVzUw)
🤖 AI解决方案
报错分析报告
1. 错误翻译
原文:The security token included in the request is invalid.
译文:请求中包含的安全令牌无效。
2. 原因分析
InvokeModel时,请求携带的AWS安全令牌(如访问密钥、会话令牌)无效或已过期。 InvokeModel操作的HTTPS请求头中的认证信息错误。3. 解决方案
python
Python示例:用boto3正确配置凭证并调用InvokeModel
import boto3
import json优先从环境变量/IAM角色获取凭证(避免硬编码)
bedrock = boto3.client("bedrock-runtime", region_name="us-east-1")try:
response = bedrock.invoke_model(
modelId="your-model-id", # 替换为实际模型ID
contentType="application/json",
accept="application/json",
body=json.dumps({"input": "测试内容"})
)
print(response["body"].read())
except Exception as e:
print(f"错误详情:{str(e)}")
修复步骤:
aws sts get-caller-identity(需安装AWS CLI); aws configure 或更新环境变量(AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/AWS_SESSION_TOKEN); 4.️ 预防措施
aws configure list查凭证状态)、IAM Access Analyzer(监控凭证滥用)。