You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python访问AWS Bedrock时遇UnrecognizedClientException错误求助

AWS Bedrock访问报错:UnrecognizedClientException

代码示例

在Jupyter Notebook中执行以下代码访问AWS Bedrock:

bedrock_client = boto3.client(
      'bedrock',
      region_name = "us-east-1",
      aws_access_key_id = "xxxxxx",
      aws_secret_access_key = "xxxxxxxxxxxxxxx"
  )
FM_list = bedrock_client.list_foundation_models()
print(FM_list)

报错详情

运行后触发错误:

ClientError: An error occurred (UnrecognizedClientException) when calling the ListFoundationModels operation: The security token included in the request is invalid.

完整异常回溯:

ClientError                               Traceback (most recent call last)
<ipython-input-17-9a9891b67e85> in <cell line: 7>()
      5           aws_secret_access_key = "xxxxxxxxxxxxxxxxxxxxxxxxx"
      6       )
----> 7 FM_list = bedrock_client.list_foundation_models()
      8 print(FM_list)

1 frames
/usr/local/lib/python3.10/dist-packages/botocore/client.py in _make_api_call(self, operation_name, api_params)
   1007             )
   1008             error_class = self.exceptions.from_code(error_code)
-> 1009             raise error_class(parsed_response, operation_name)
   1010         else:
   1011             return parsed_response

已尝试操作

已更换多个从企业SSO账号获取的临时凭证,获取路径为AWS控制台的「命令行或编程访问」页面。


解决方法

  1. 补充会话令牌参数
    企业SSO生成的是临时凭证,必须同时传入aws_session_token,修改代码:
bedrock_client = boto3.client(
    'bedrock',
    region_name = "us-east-1",
    aws_access_key_id = "你的临时访问密钥ID",
    aws_secret_access_key = "你的临时秘密访问密钥",
    aws_session_token = "你的会话令牌"
)
  1. 检查凭证有效期
    临时凭证默认有效期12小时,重新获取最新的凭证再测试。

  2. 验证权限配置
    确认你的SSO账号被分配了bedrock:ListFoundationModels权限,联系管理员检查IAM策略。

  3. 确认区域可用性
    us-east-1区域支持Bedrock,但如果仍有问题,可切换到us-west-2等已开放的区域测试。

内容的提问来源于stack exchange,提问作者jereesh thomas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 02:00:20