简体   繁体   中英

How to delete Rds instance along with Rds cluster using boto3 in AWS

I need to delete the RDS instance and RDS cluster using boto3

Note : I am creating the RDS instance under the cluster in Amazon console.

I used the below codes however getting error:

Syntax error in module 'lambda_function': expected an indented block (lambda_function.py, line 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

I need to delete RDS cluster and RDS db instances

NOTE: It would be better if it is possible in all regions in my account

Your for loop at the bottom is not indented properly, should be something like below:

    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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM