python - boto3 客户端 NoRegionError : You must specify a region error only sometimes

标签 python linux amazon-web-services boto3 aws-kms

我有一个 boto3 客户端:

boto3.client('kms')

但它发生在新机器上,它们动态打开和关闭。

    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()

为什么会这样?为什么只有一部分时间?

最佳答案

您必须以一种或另一种方式告诉 boto3 您希望在哪个区域创建 kms 客户端。这可以使用 region_name 参数显式完成,如下所示:

kms = boto3.client('kms', region_name='us-west-2')

或者您可以在 ~/.aws/config 文件中设置与您的配置文件关联的默认区域,如下所示:

[default]
region=us-west-2

或者您可以使用如下环境变量:

export AWS_DEFAULT_REGION=us-west-2

但您确实需要告诉 boto3 使用哪个区域。

关于python - boto3 客户端 NoRegionError : You must specify a region error only sometimes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40377662/

相关文章:

amazon-web-services - 启用 AWS Group 访问 AWS EKS 集群

python - 更改 ipython 中的输出字体

python - Django 1.8 - 信号 - @receiver 装饰器和 Signal.connect() 方法有什么区别?

python-3.x - PyInstaller 到 linux 中的可执行文件,给出 : error running upx -v?

javascript - 如何使用 Sharp 从 S3 调整图像大小?

amazon-web-services - AWS Lambda 函数在第一次调用时超时,在第二次调用时工作

python - 使用 Python 以 MySQL 格式打印结果

python - 我正在尝试将数字数据类型的行中的所有 NaN 值填充为 pandas 中的零

linux - Bash 别名在文件名中创建具有当前时间戳的文件

python - 将最佳拟合及其方程放入绘图中