【问题标题】:How to delete Rds instance along with Rds cluster using boto3 in AWS如何在 AWS 中使用 boto3 删除 Rds 实例和 Rds 集群
【发布时间】:2019-08-22 10:24:50
【问题描述】:

我需要使用boto3删除RDS实例和RDS集群

注意:我在 Amazon 控制台的集群下创建 RDS 实例。

我使用了以下代码,但出现错误:

模块“lambda_function”中的语法错误:需要一个缩进块(lambda_function.py,第 25 行)

    ec2 = boto3.client('ec2')

    # Get list of regions
    regions = ec2.describe_regions().get('Regions',[] )

    # Iterate over regions
    for region in regions:

        # Running following for a particular region
        print ("*************** Checking region  --   %s " % region['RegionName'])
        reg=region['RegionName']

    ####### deleting rds cluster ###############

    print ("++++++++++++++ Deleting RDS cluster ++++++++++++++")
    client = boto3.client('rds')
    response = client.describe_db_instance(Filters=[{'Name': 'string'}]
    for instance in response ["DBInstances"]:
       print ("About to delete %s | in %s" % (instance['DBInstanceIdentifier']))
       response = client.delete_db_instance(DBInstanceIdentifier=instance['DBInstanceIdentifier'])
       SkipFinalSnapshot=True
       DeleteAutomatedBackups=True

我需要删除 RDS 集群和 RDS db 实例

注意:如果在我的帐户中的所有区域都可以,那就更好了

【问题讨论】:

    标签: amazon-web-services boto3 amazon-rds


    【解决方案1】:

    底部的for 循环没有正确缩进,应该如下所示:

        for cluster in result ["rds"]:
            print ("About to delete %s | in %s" % (cluster['DBInstanceIdentifier']))
            response = client.delete_db_instance(DBInstanceIdentifier=cluster['DBInstanceIdentifier'])
            SkipFinalSnapshot=True
            DeleteAutomatedBackups=True
    

    【讨论】:

    • @Biplob Biswas 我仍然面临删除问题。您知道脚本应该如何吗?我需要使用 boto3 删除所有区域中的 Rds 实例吗?
    • @MuneeshDuRaipandi 你能提供更多关于这个问题的细节吗?您如何创建 rds 实例、cloudformation 或 cli 或控制台?它是集群的一部分还是只是独立实例?也许更新你的问题,然后我也可以更新答案
    • @Biplob Biswas 我已经更新了这个问题。我在 AWS 控制台的集群下创建 RDS 实例,我需要使用 boto3 删除集群和 RDS 实例。
    猜你喜欢
    • 2022-11-05
    • 2017-11-28
    • 2018-09-15
    • 2015-09-21
    • 2018-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-29
    相关资源
    最近更新 更多