使用boto3调用Bedrock-Runtime客户端时遭遇UnknownServiceError错误
boto3调用Bedrock-Runtime报UnknownServiceError的解决方法
问题重现
执行以下代码创建Bedrock-Runtime客户端时触发错误:
client = boto3.client(service_name='bedrock-runtime',region_name='us-west-1')
错误栈信息:
UnknownServiceError Traceback (most recent call last) Cell In[7], line 1 ----> 1 client = boto3.client(service_name='bedrock-runtime',region_name='us-west-1') File ~/anaconda3/envs/python3/lib/python3.10/site-packages/boto3/__init__.py:92, in client(*args, **kwargs) 86 def client(*args, **kwargs):
解决步骤
- 升级boto3和botocore版本:Bedrock-Runtime是AWS较新推出的服务,旧版本boto3未包含该服务的API定义。执行下方命令升级:
pip install --upgrade boto3 botocore - 验证区域支持性:确认
us-west-1区域是否提供Bedrock-Runtime服务。若该区域不支持,替换为AWS官方明确支持的区域(例如us-east-1、us-west-2)。 - 检查凭证与权限:确保AWS凭证配置正确(环境变量、
~/.aws/credentials文件等方式),且当前凭证拥有访问Bedrock-Runtime服务的权限。
内容的提问来源于stack exchange,提问作者user3858193
相关产品推荐
相关产品推荐

