agent: |
P4qaH1250SIEww4JwKp6List All AWS RDS Instances
List All AWS RDS Instances
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
This task involves enumerating and displaying all AWS RDS (Amazon Relational Database Service) instances within an AWS account. This task is essential for management and auditing purposes, providing a clear view of all RDS instances. During this process, the script communicates with AWS services to retrieve information about each RDS instance, including their identifiers, status, and any other relevant details. This information is crucial for administrators to understand their AWS infrastructure's state, aiding in further actions like modification, deletion, or analysis of the RDS instances.
inputs
outputs
import boto3
from botocore.exceptions import BotoCoreError, ClientError
reg=None # Runs for specific region if provided otherwise runs for all regions if None/nothing is provided.
creds = _get_creds(cred_label)['creds']
access_key = creds['username']
secret_key = creds['password']
def list_all_rds_instances(region=None):
try:
if region:
regions = [region]
else:
# If region is None, list instances in all available regions
ec2 = boto3.client('ec2', aws_access_key_id=access_key,aws_secret_access_key=secret_key,region_name='us-east-1')
regions = [region['RegionName'] for region in ec2.describe_regions()['Regions']]
all_instances = []
for region in regions:
#print(f"Listing RDS instances in region {region}:")
client = boto3.client('rds', aws_access_key_id=access_key,aws_secret_access_key=secret_key,region_name=region)
try:
db_instances = client.describe_db_instances()
region_instances = [instance['DBInstanceIdentifier'] for instance in db_instances['DBInstances']]
if region_instances:
print(f"Found {len(region_instances)} RDS instances in region {region}:")
for instance in region_instances:
print(instance)
all_instances.append({"region": region, "instance": instance})
else:
#print(f"No RDS instances found in region {region}.")
p=1 # dummy line to end the conditional block properly
except ClientError as e:
print(f"Client error in region {region}: {e}")
except BotoCoreError as e:
print(f"BotoCoreError in region {region}: {e}")
except Exception as e:
print(f"Unexpected error in region {region}: {e}")
return all_instances
except Exception as e:
print(f"Unexpected error: {e}")
instances = list_all_rds_instances(reg) # reg is initialized in input parameters. Runs for specific region if provided otherwise runs for all regions if None/nothing is provided.
#print(instances)
copied