agent: |
UPvGHQhw9slZ91wvq0PKList AWS RDS Instances of a specific instance type
List AWS RDS Instances of a specific instance type
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
In AWS, users can manage multiple RDS (Relational Database Service) instances for various database workloads. This task can be used to identify RDS instances based on a specific instance type, perhaps for auditing, cost optimization, or migration purposes. By using this task users can filter and list all RDS instances that match a particular instance type. This allows for a more streamlined management process and aids in making informed decisions regarding scaling, performance tuning, or cost management.
inputs
outputs
import boto3
creds = _get_creds(cred_label)['creds']
access_key = creds['username']
secret_key = creds['password']
def list_specific_rds_instances(region=None):
old_gen_instances = {}
# List of regions to check
try:
ec2_client = boto3.client('ec2',aws_access_key_id=access_key,aws_secret_access_key=secret_key,region_name='us-east-1')
regions_to_check = [region] if region else [region['RegionName'] for region in ec2_client.describe_regions()['Regions']]
except Exception as e:
print(f"Error listing AWS regions: {e}")
regions_to_check = [region] if region else []
for region in regions_to_check:
try:
rds = boto3.client('rds',aws_access_key_id=access_key,aws_secret_access_key=secret_key, region_name=region) # Creating the RDS client for the specified region
paginator = rds.get_paginator('describe_db_instances')
for page in paginator.paginate():
for instance in page['DBInstances']:
if instance_type_to_match in instance['DBInstanceClass']: # Replace with the actual type you are matching
old_gen_instances.setdefault(region, []).append(instance['DBInstanceIdentifier'])
except rds.exceptions.DBInstanceNotFoundFault:
print(f"Specific error in region {region}: DB Instance not found.")
except Exception as e:
print(f"General error listing RDS instances in region {region}: {e}")
return old_gen_instances
# Set region to None for all regions, or specify a valid AWS region string for a specific region
#target_region = None
#instance_type_to_match = 'db.m4' # Replace with your actual instance type to match
# List RDS instances that are of the matching type
old_gen_instances = list_specific_rds_instances(target_region)
# Print the results
if old_gen_instances:
print("Matching RDS instances found:")
for region, instances in old_gen_instances.items():
print(f"In region {region}:")
for instance_id in instances:
print(f" - {instance_id}")
else:
print("No such RDS instances found.")
context.proceed = False
copied