-
Notifications
You must be signed in to change notification settings - Fork 0
/
tool_aws_list_rds_instances.py
49 lines (40 loc) · 1.58 KB
/
tool_aws_list_rds_instances.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import boto3
from langchain.tools import tool
def do_list_rds_instances(region: str):
rds = boto3.client('rds', region)
response = rds.describe_db_instances()
instances = response['DBInstances']
results = []
for instance in instances:
results.append({
'DBInstanceIdentifier': instance['DBInstanceIdentifier'],
'Engine': instance['Engine'],
'DBInstanceStatus': instance['DBInstanceStatus'],
'DBInstanceClass': instance['DBInstanceClass'],
'Endpoint': instance.get('Endpoint', {}).get('Address', 'N/A')
})
return results
@tool
def list_rds_instances(region: str) -> str:
"""
Lists all RDS instances in a specified AWS account and region.
Args:
region (str): The AWS region to use.
Returns:
str: A summary report of all RDS instances in the specified account and region.
"""
try:
instances = do_list_rds_instances(region)
if not instances:
return f"No RDS instances found in the {region} region."
report = "RDS Instances:\n"
for instance in instances:
report += f"\nIdentifier: {instance['DBInstanceIdentifier']}"
report += f"\n Engine: {instance['Engine']}"
report += f"\n Status: {instance['DBInstanceStatus']}"
report += f"\n Instance Class: {instance['DBInstanceClass']}"
report += f"\n Endpoint: {instance['Endpoint']}"
report += "\n"
return report
except Exception as e:
return f"Error listing RDS instances: {e}"