1- """
2- AWS service integration tool for Strands Agent.
1+ """AWS service integration tool for Strands Agent.
32
43This module provides a comprehensive interface to AWS services through boto3,
54allowing you to invoke any AWS API operation directly from your Strands Agent.
5453import boto3
5554from botocore .exceptions import ParamValidationError , ValidationError
5655from botocore .response import StreamingBody
57- from colorama import Fore , Style , init
56+ from rich import box
5857from rich .panel import Panel
58+ from rich .table import Table
5959from strands .types .tools import ToolResult , ToolUse
6060
6161from strands_tools .utils import console_util
6262from strands_tools .utils .data_util import convert_datetime_to_str
6363from strands_tools .utils .generate_schema_util import generate_input_schema
6464from strands_tools .utils .user_input import get_user_input
6565
66- # Initialize colorama
67- init (autoreset = True )
68-
6966logger = logging .getLogger (__name__ )
7067
7168MUTATIVE_OPERATIONS = [
@@ -102,8 +99,7 @@ def get_boto3_client(
10299 region_name : str ,
103100 profile_name : Optional [str ] = None ,
104101) -> Any :
105- """
106- Create an AWS boto3 client for the specified service and region.
102+ """Create an AWS boto3 client for the specified service and region.
107103
108104 Args:
109105 service_name: Name of the AWS service (e.g., 's3', 'ec2', 'dynamodb')
@@ -118,8 +114,7 @@ def get_boto3_client(
118114
119115
120116def handle_streaming_body (response : Dict [str , Any ]) -> Dict [str , Any ]:
121- """
122- Process streaming body responses from AWS into regular Python objects.
117+ """Process streaming body responses from AWS into regular Python objects.
123118
124119 Some AWS APIs return StreamingBody objects that need special handling to
125120 convert them into regular Python dictionaries or strings for proper JSON serialization.
@@ -141,8 +136,7 @@ def handle_streaming_body(response: Dict[str, Any]) -> Dict[str, Any]:
141136
142137
143138def get_available_services () -> List [str ]:
144- """
145- Get a list of all available AWS services supported by boto3.
139+ """Get a list of all available AWS services supported by boto3.
146140
147141 Returns:
148142 List of service names as strings
@@ -152,8 +146,7 @@ def get_available_services() -> List[str]:
152146
153147
154148def get_available_operations (service_name : str ) -> List [str ]:
155- """
156- Get a list of all available operations for a specific AWS service.
149+ """Get a list of all available operations for a specific AWS service.
157150
158151 Args:
159152 service_name: Name of the AWS service (e.g., 's3', 'ec2')
@@ -289,14 +282,23 @@ def use_aws(tool: ToolUse, **kwargs: Any) -> ToolResult:
289282
290283 STRANDS_BYPASS_TOOL_CONSENT = os .environ .get ("BYPASS_TOOL_CONSENT" , "" ).lower () == "true"
291284
292- # Create a panel for AWS Operation Details
293- operation_details = f"{ Fore .CYAN } Service:{ Style .RESET_ALL } { service_name } \n "
294- operation_details += f"{ Fore .CYAN } Operation:{ Style .RESET_ALL } { operation_name } \n "
295- operation_details += f"{ Fore .CYAN } Parameters:{ Style .RESET_ALL } \n "
296- for key , value in parameters .items ():
297- operation_details += f" - { key } : { value } \n "
285+ # Create a panel for AWS Operation Details using Rich's native styling
286+ details_table = Table (show_header = False , box = box .SIMPLE , pad_edge = False )
287+ details_table .add_column ("Property" , style = "cyan" , justify = "left" , min_width = 12 )
288+ details_table .add_column ("Value" , style = "white" , justify = "left" )
289+
290+ details_table .add_row ("Service:" , service_name )
291+ details_table .add_row ("Operation:" , operation_name )
292+ details_table .add_row ("Region:" , region )
293+
294+ if parameters :
295+ details_table .add_row ("Parameters:" , "" )
296+ for key , value in parameters .items ():
297+ details_table .add_row (f" • { key } :" , str (value ))
298+ else :
299+ details_table .add_row ("Parameters:" , "None" )
298300
299- console .print (Panel (operation_details , title = label , expand = False ))
301+ console .print (Panel (details_table , title = f"[bold blue]🚀 { label } [/bold blue]" , border_style = "blue" , expand = False ))
300302
301303 logger .debug (
302304 "Invoking: service_name = %s, operation_name = %s, parameters = %s" % (service_name , operation_name , parameters )
@@ -321,7 +323,7 @@ def use_aws(tool: ToolUse, **kwargs: Any) -> ToolResult:
321323 # Check AWS service
322324 available_services = get_available_services ()
323325 if service_name not in available_services :
324- logger .debug (f"{ Fore . RED } Invalid AWS service: { service_name } { Style . RESET_ALL } " )
326+ logger .debug (f"Invalid AWS service: { service_name } " )
325327 return {
326328 "toolUseId" : tool_use_id ,
327329 "status" : "error" ,
@@ -333,7 +335,7 @@ def use_aws(tool: ToolUse, **kwargs: Any) -> ToolResult:
333335 # Check AWS operation
334336 available_operations = get_available_operations (service_name )
335337 if operation_name not in available_operations :
336- logger .debug (f"{ Fore . RED } Invalid AWS operation: { operation_name } { Style . RESET_ALL } " )
338+ logger .debug (f"Invalid AWS operation: { operation_name } " )
337339 return {
338340 "toolUseId" : tool_use_id ,
339341 "status" : "error" ,
0 commit comments