[英]How do I Start/Stop AWS RDS Instances using Boto?
I had a question about Amazon RDS. 我对Amazon RDS有疑问。 I wanted to Start/Stop AWS RDS Instances at my need . 我想根据需要启动/停止AWS RDS实例。 AWS Console does not allow me to do so. AWS控制台不允许我这样做。
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. 我知道的唯一方法是拍摄rds实例的快照并将其删除,然后在需要时使用该快照创建rds实例。 Is there any better way to acheive the same using Boto? 有没有更好的方法可以使用Boto达到相同的效果?
They recently added support: https://aws.amazon.com/about-aws/whats-new/2017/06/amazon-rds-supports-stopping-and-starting-of-database-instances/ 他们最近增加了支持: https : //aws.amazon.com/about-aws/whats-new/2017/06/amazon-rds-supports-stopping-and-starting-of-database-instances/
Assuming you can use boto3... 假设您可以使用boto3 ...
Start: http://boto3.readthedocs.io/en/latest/reference/services/rds.html#RDS.Client.start_db_instance 开始: http : //boto3.readthedocs.io/en/latest/reference/services/rds.html#RDS.Client.start_db_instance
Stop: http://boto3.readthedocs.io/en/latest/reference/services/rds.html#RDS.Client.stop_db_instance 停止: http : //boto3.readthedocs.io/en/latest/reference/services/rds.html#RDS.Client.stop_db_instance
No, that's probably the best you can do. 不,这可能是您可以做的最好的事情。 The RDS API does not support the Stop/Start functionality of EC2 instances. RDS API不支持EC2实例的停止/启动功能。
Yes, just to add Venkata answer now you can start/stop instance using boto3. 是的,现在只需添加Venkata答案,您就可以使用boto3启动/停止实例。 I created an aws lambda which start/stop my rds instances, using boto3 start_db_instance, stop_db_instance as the following: 我创建了一个aws lambda,它使用boto3 start_db_instance,stop_db_instance如下启动/停止我的rds实例:
Start instance: import boto3 开始实例: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. 不要忘记,名为DBInstanceIdentifier的参数应该是您在创建它时提供的rds实例名称。
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. 要记住的重要一件事是,您应该为lambda提供一个角色,如果要启动/停止rds,则应设置一个至少具有此权限的角色。
You can only start or stop AWS RDS instance of single availability zone instances. 您只能启动或停止单个可用性区域实例的AWS RDS实例。 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. 如果您的数据库位于“多个可用性”区域中,最好的方法是获取快照并还原它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.