【问题标题】:Python and Boto3 object method NoRegionError()?Python 和 Boto3 对象方法 NoRegionError()?
【发布时间】:2018-05-26 03:50:40
【问题描述】:

我在我的代码中打印出 AWS_REGION 的 env 变量值,以便我可以确认该变量确实存在,但我仍然从 Boto3 对象实例方法获得 NoRegionError()。我如何确认 Boto3 方法期望什么,以便我更正此错误?另外,“客户端”对象不使用 AWS_REGION 环境变量吗?

if choice == 'a'
            st_id = "xxxdhfda-sfffg"
            print("st id is:")
            print(st_id)
            print("region is:")
            print(os.environ['AWS_REGION'])
            #sfleet.cancel_sfleet_request(sfleet)
            # low level ec2 client
            client = boto3.client('ec2')
            client.cancel_spot_fleet_requests(
                SpotFleetRequestIds = [ st_id ],
                TerminateInstances=True
            )
        else:
            return False

输出:

region is:
us-east-1
:
:
:

      File "/usr/lib/python2.7/site-packages/botocore/regions.py", line 135, in _endpoint_for_partition
        raise NoRegionError()
    NoRegionError: You must specify a region.

【问题讨论】:

    标签: python amazon-web-services amazon-ec2 boto3


    【解决方案1】:

    您想设置AWS_DEFAULT_REGION,而不是AWS_REGION。请参阅documented list of env. variables 了解 boto3。

    【讨论】:

      猜你喜欢
      • 2019-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-15
      • 2021-11-12
      • 1970-01-01
      • 2016-09-05
      • 1970-01-01
      相关资源
      最近更新 更多