我有多个aws帐户,我想通过脚本管理大部分工作。我能够连接到ELB,EC2使用boto,但我无法找到相同的机制与RDS工作。
用于EC2连接我的示例功能如下所示:
def Ec2Conn(reg,profile = 'default'):
ec2conn = ''
try:
ec2conn = boto.ec2.EC2Connection(profile_name=profile, region=boto.ec2.get_region(reg.strip()))
except Exception, e:
boto.log.error("Cannot validate provided AWS credentials: %s" % e)
return(ec2conn)如果reg( region )传递给function,它将读取,否则它将选择aws boto中的默认区域设置。类似地,如果没有为配置文件提供任何选项,它将从boto获取默认配置文件。
但是,我不能对RDS连接做同样的事情。
我认为示例代码可以用于与boto配置文件的RDS连接,但不幸的是,它不能正常工作:
def RDSConn(reg,profile = 'default'):
rdsconn = ''
try:
rdsconn = boto.rds2.connect_to_region(region=boto.ec2.get_region(reg.strip()), profile_name=profile)
except Exception, e:
boto.log.error("Cannot validate provided AWS credentials: %s" % e)
return(elbconn)Oops这是敬畏!!:
>>> dir(boto.rds2)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'connect_to_region', 'get_regions', 'regions']
>>>Boto rds2中没有任何配置文件的方法。
在我的盒子上运行的Boto版本如下:
>>> print boto.Version
2.39.0任何面临同样问题的人。任何建议,请。
发布于 2016-04-06 11:56:46
谢谢大家的建议。我正在制作一个模块,用于访问aws中的多个服务,现在已经完成了。我不需要知道aws密钥,秘密密钥和所有,一次我自动化了我的东西。
我使用下面的方法修复rds连接问题:
def RDSConn(reg,profile = 'default'):
rdsconn = ''
endpt = 'rds.' + reg + '.amazonaws.com'
reg = boto.regioninfo.RegionInfo(name=reg,endpoint=endpt)
try:
rdsconn=boto.connect_rds2(profile_name=profile, region=reg)
except Exception, e:
boto.log.error("Cannot validate provided AWS credentials: %s" % e)
return(rdsconn)发布于 2016-03-30 14:21:41
region不是可选key=value参数的一部分,它是必需的参数。boto.ec2.connect_to_region也是如此。
connect_to_region(region_name, **kw_params)所以你的代码应该是:
rdsconn = boto.rds2.connect_to_region(boto.ec2.get_region(reg.strip()), profile_name=profile)发布于 2016-03-30 08:53:51
这是通常的AWS摘要(AKA糟糕的文档),您必须找到散落各地的信息。(Python ()也没有给您多少信息)
这是工作的示例代码。假设您有一个~/..aws/凭据文件,文件中有一个默认条目。(解决方案示例在这里找到http://boto3.readthedocs.org/en/latest/guide/configuration.html )
rds_conn = boto.rds2.connect_to_region("eu-central-l", profile_name="default")
#you cannot specifiy region=, and things like profile_name= not mentioned as argumentsAWS改变了boto.rds2的参数传递方式,它使用的方法与boto3非常相似。
https://stackoverflow.com/questions/36302073
复制相似问题