Reputation: 257
I have multiple aws account and I want to manage most of the work via script. I am able to connect to ELB, EC2 using boto profile however I am not able to find out the same mechanism to work with RDS.
For EC2 connection my sample fucntion looks like this :
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)
If reg(region) passed to function it will read that else it will select the region set default in aws boto. Similarly if no option given for profile it takes default profile from boto.
However I am unable to do the same with RDS connection.
Sample code which I thought could work for RDS connection with boto profile but unfortunately not working :
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 this is awe!! :
>>> dir(boto.rds2)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'connect_to_region', 'get_regions', 'regions']
>>>
Boto rds2 does not have any method for profile in it.
Boto version I am running on my box is as below :
>>> print boto.Version
2.39.0
Any one who faced the same issue. Any suggestion plz.
Upvotes: 0
Views: 728
Reputation: 257
Thanks all for your suggestion. I was making a module for accessing multiple services at aws which is completed now. I do not need to know the aws key, secret key and all , once for all I automated my stuff.
I used below way to fix rds connection issue :
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)
Upvotes: 0
Reputation: 52433
region
is not part of optional key=value
parameter, it is a required parameter. It is true for boto.ec2.connect_to_region
too.
connect_to_region(region_name, **kw_params)
So your code should be:
rdsconn = boto.rds2.connect_to_region(boto.ec2.get_region(reg.strip()), profile_name=profile)
Upvotes: 1
Reputation: 13176
This is usual AWS summarised (AKA poor documentation) that you must find info scattered around. (Python help() doesn't give you much info either)
This is the sample code that works. Assume you have a ~/.aws/credential file, with a [default] entry in the file. (the solution sample is found here 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 arguments
AWS change the way of argument passing for boto.rds2, which using method closely resemble to boto3.
Upvotes: 0