boto3客户端NoRegionError:仅在某些情况下必须指定区域错误 [英] boto3 client NoRegionError: You must specify a region error only sometimes
问题描述
我有一个boto3客户端:
I have a boto3 client :
boto3.client('kms')
但是它发生在新机器上,它们会动态打开和关闭.
But it happens on new machines, They open and close dynamically.
if endpoint is None:
if region_name is None:
# Raise a more specific error message that will give
# better guidance to the user what needs to happen.
raise NoRegionError()
为什么会这样?为什么只有部分时间呢?
Why is this happening? and why only part of the time?
推荐答案
您必须以一种或另一种方式告诉boto3您希望在哪个区域创建kms
客户端.可以使用region_name
参数明确完成此操作,如下所示:
One way or another you must tell boto3 in which region you wish the kms
client to be created. This could be done explicitly using the region_name
parameter as in:
kms = boto3.client('kms', region_name='us-west-2')
,或者您可以在~/.aws/config
文件中将与您的个人资料相关联的默认区域设置为:
or you can have a default region associated with your profile in your ~/.aws/config
file as in:
[default]
region=us-west-2
或者您可以使用如下环境变量:
or you can use an environment variable as in:
export AWS_DEFAULT_REGION=us-west-2
但是您确实需要告诉boto3使用哪个区域.
but you do need to tell boto3 which region to use.
这篇关于boto3客户端NoRegionError:仅在某些情况下必须指定区域错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!