Looping through tagged resources in AWS RDS

0 votes
 I'm trying to target clusters based on their tag. In the code below I can target the cluster with the tag AutoOn and true. If I have one other cluster with tags how can I also include that in my script so I can also start it up? Is it another if statement?
def handler(event, context):
# Step one: get all DB clusters.
    response = rds_client.describe_db_clusters(
        MaxRecords=100
    )

    # Make an empty list for cluster info storage.
    clusters = [] # empty list of no items.

    # Get the initial results.
    clusters.append(response['DBClusters'])

    # If 'Marker' is present in the response, we have more to get.
    while 'Marker' in response:
        old_marker = response['Marker']
        response = rds_client.describe_db_clusters(
            MaxRecords=100,
            Marker = old_marker
        )
        clusters.append(response['DBClusters'])
        # Cycles back up to repeat the pagination.

    for cluster in clusters:
        for test in cluster:
            for tag in test['TagList']:
                if tag['Key'] == "AutoOn":
                    if tag['Value'] == "true":
                        continue  # move to the next record.

        # Stop the instance.
        rds_client.start_db_cluster(
            DBClusterIdentifier=test['DBClusterIdentifier']
        )

I tried this as a way to target cluster 1 AND cluster 2. The code runs fine in a Lambda function and doesn't produce any errors but it doesn't start the RDS clusters.

for tag in test['TagList']:
    if ('Key' == 'AutoOn'
          and 'Value' == 'true'
            ): 
             
    if ('Key' == 'AutoOn2'
          and 'Value' == 'true'):
             rds_client.start_db_cluster(
        DBClusterIdentifier=test['DBClusterIdentifier']


Any help would be appreciated.
Apr 9, 2022 in Others by Kichu
• 19,040 points
502 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Others

0 votes
0 answers

Upgrade instance type from r4 to r5 in AWS RDS

I am currently using an r4 instance. Model ...READ MORE

Apr 10, 2022 in Others by Kichu
• 19,040 points
858 views
0 votes
0 answers

Read replicas in RDS AWS

My questions are: For what kind of applications ...READ MORE

Apr 10, 2022 in Others by Kichu
• 19,040 points
457 views
0 votes
1 answer

How to create subnet inside a VPC in AWS using Terraform?

Hi@akhtar, You need to use aws_subnet resource inside your ...READ MORE

answered Jul 21, 2020 in Others by MD
• 95,460 points
694 views
0 votes
1 answer

What is Elastic IP in AWS and why it is useful?

A static public IPv4 address connected with ...READ MORE

answered Feb 8, 2022 in Others by Edureka
• 13,620 points
749 views
+1 vote
2 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP