简体   繁体   English

无法使用 boto3 连接到 AWS 区域

[英]Not able to connect to AWS region using boto3

I am not able to connect to to any region using boto3 i have tried everything using boto3.session.Session, connection = ec2.connect_to_region我无法使用 boto3 连接到任何区域我已经尝试了所有使用 boto3.session.Session, connection = ec2.connect_to_region

connection=ec2.connect_to_region('region_name',aws_access_key_id='',aws_secret_access_key='' connection=ec2.connect_to_region('region_name',aws_access_key_id='',aws_secret_access_key=''

I am getting the below error:我收到以下错误:

File "/usr/local/lib/python2.7/site-packages/botocore/regions.py", line 135, in _endpoint_for_partition raise NoRegionError() botocore.exceptions.NoRegionError: You must specify a region.文件“/usr/local/lib/python2.7/site-packages/botocore/regions.py”,第 135 行,在 _endpoint_for_partition 中 raise NoRegionError() botocore.exceptions.NoRegionError:您必须指定一个区域。

Your code should look like this:您的代码应如下所示:

import boto
conn = boto.ec2.connect_to_region("us-west-2",
    aws_access_key_id='<aws access key>',
    aws_secret_access_key='<aws secret key>')

However, I recommend that you drop using boto and switch to boto3 unless you have a technical reason.但是,除非您有技术原因,否则我建议您放弃使用 boto 并切换到 boto3。

import boto3
client = boto3.client(
    'ec2',
    aws_access_key_id='<aws access key>',
    aws_secret_access_key='<aws secret key>',
    region_name="us-west-2"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM