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.