How do I Start/Stop AWS RDS Instances using Boto?

5.2k views Asked by At

I had a question about Amazon RDS. I wanted to Start/Stop AWS RDS Instances at my need . AWS Console does not allow me to do so.

The Only method I know is to take a snapshot of the rds instance and delete it and when I need it then a create rds instance using that snapshot. Is there any better way to acheive the same using Boto?

4

There are 4 answers

0
garnaat On BEST ANSWER

No, that's probably the best you can do. The RDS API does not support the Stop/Start functionality of EC2 instances.

0
Rohit Sidhwani On

You can only start or stop AWS RDS instance of single availability zone instances. For your case, you will have to check if the multi-AZ option is enabled or disabled.

Incase your database is in Multiple availability zone, the best way would be to take the snapshot and restore it.

0
Paulo Victor On

Yes, just to add Venkata answer now you can start/stop instance using boto3. I created an aws lambda which start/stop my rds instances, using boto3 start_db_instance, stop_db_instance as the following:

Start instance: import boto3

def handler(event, context):
    rds = boto3.client('rds', region_name='us-east-1')
    response = rds.start_db_instance(DBInstanceIdentifier='mydb-instance-name') #it should be rds instance NAME 

Stop instance:

import boto3

def handler(event, context):
    rds = boto3.client('rds', region_name='us-east-1')
    response = rds.stop_db_instance(DBInstanceIdentifier='mydb-instance-name') #it should be rds instance NAME 

Don't forget, the parameter called DBInstanceIdentifier should be the rds instance name provided by you when you created it.

One important thing to remember is, you should provide a role to your lambdas, and if you want to start/stop rds you should set one role which has at least this permissions.