Sign in
agent:

Filter out Publicly Accessible AWS RDS Instances

There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.

This task is essential for identifying databases that are exposed to the internet, potentially posing security risks. This process involves scanning through all active AWS RDS instances in a given AWS account and pinpointing those configured to be publicly accessible. Publicly accessible in this context means that the RDS instance is reachable from the internet and not just within a private network or Virtual Private Cloud (VPC). By isolating these instances, administrators can take necessary actions to secure sensitive data, either by modifying the accessibility settings or implementing additional security measures. This task is crucial for maintaining a secure and compliant cloud environment, as it helps prevent unauthorized access and data breaches.

import boto3 from botocore.exceptions import BotoCoreError, ClientError creds = _get_creds(cred_label)['creds'] access_key = creds['username'] secret_key = creds['password'] def filter_public_rds_instances(all_instances): public_instances = [] try: for instance_info in all_instances: region = instance_info['region'] instance = instance_info['instance'] print(f"Checking for public accessibility of RDS instance {instance} in region {region}:") client = boto3.client('rds', aws_access_key_id=access_key,aws_secret_access_key=secret_key,region_name=region) try: instance_details = client.describe_db_instances(DBInstanceIdentifier=instance) if instance_details['DBInstances'][0]['PubliclyAccessible']: public_instances.append({"region": region, "instance": instance}) print(f"{instance} in region {region} is publicly accessible.") except ClientError as e: print(f"Client error with instance {instance} in region {region}: {e}") except BotoCoreError as e: print(f"BotoCoreError with instance {instance} in region {region}: {e}") except Exception as e: print(f"Unexpected error with instance {instance} in region {region}: {e}") if not public_instances: print("No publicly accessible RDS instances found in the provided list.") except Exception as e: print(f"Unexpected error: {e}") return public_instances # Example list of all RDS instances and regions. Replace this with the actual data from your AWS account. # all_instances = [{'region': 'us-east-1', 'instance': 'database-1'},{'region': 'us-west-1', 'instance': 'database-1'}] # Example data # instances passed down from parent task all_instances = instances public_instances = filter_public_rds_instances(all_instances) #print(public_instances) context.proceed = False
copied