简体   繁体   English

如何使用Boto启动/停止AWS RDS实例?

[英]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达到相同的效果?

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.

相关问题 boto3使用AWS Lambda启动/停止RDS实例 - boto3 start/stop RDS instance with AWS Lambda 使用 Boto 列出 RDS 保留实例? - Listing RDS reserved instances using Boto? 如何使用 boto3 RDS 客户端 Z2778840A0100CB30C982876741B0B5A2Z 服务器 select 查询在 AWS lambda 中运行 - How to run RDS SQL Server select queries in AWS lambda using boto3 RDS client python? 如何使用 boto3 create_instances() 分配安全组和子网? - How do I assign security groups and subnet using boto3 create_instances()? 使用boto修改AWS RDS中的数据库参数组 - Modify db parameter group in AWS RDS using boto 使用boto(AWS Python),如何获取IAM用户列表? - Using boto (AWS Python), how do I get a list of IAM users? 如何使用boto更改我的AWS Route53注册域的名称服务器? - How do I change the nameservers for my AWS Route53 Registered Domain using boto? 如何在 python 中使用 boto3 访问 AWS 参数存储中的参数描述? - How do I access a parameter's description in AWS parameter store, using boto3 in python? 如何使用 BOTO python 在 AWS 中获取实例的公共 dns - How do i get the public dns of an instance in AWS using BOTO python 如何测试依赖于boto和Amazon AWS服务的模块? - How do I test a module that depends on boto and an Amazon AWS service?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM