from typing import Any, Dict from aws.lambda_client import LambdaClient from aws.sfn_client import StepFunctionsClient from aws.s3_client import S3Client # Initialize AWS clients lambda_client = LambdaClient() sfn_client = StepFunctionsClient() s3_client = S3Client() def invoke_lambda(function_name: str, payload: Dict[str, Any], async_invoke: bool = False) -> Dict[str, Any]: """ Invoke a Lambda function. Args: function_name: Name or ARN of the Lambda function payload: Input payload for the function async_invoke: Whether to invoke asynchronously (default: False for synchronous) Returns: Lambda response or error message """ try: result = lambda_client.invoke(function_name, payload, async_invoke) return { "status": "success", "function": function_name, "result": result } except Exception as e: return {"status": "error", "message": str(e)} def list_lambda_functions() -> Dict[str, Any]: """ List all Lambda functions in the account. Returns: List of Lambda functions """ try: functions = lambda_client.list_functions() if isinstance(functions, dict) and "error" in functions: return functions return { "status": "success", "count": len(functions), "functions": functions } except Exception as e: return {"status": "error", "message": str(e)} def get_lambda_info(function_name: str) -> Dict[str, Any]: """ Get detailed information about a Lambda function. Args: function_name: Name or ARN of the Lambda function Returns: Function configuration and metadata """ try: info = lambda_client.get_function_info(function_name) if "error" in info: return info return { "status": "success", "info": info } except Exception as e: return {"status": "error", "message": str(e)} def start_sfn_execution(state_machine_arn: str, input_data: Dict[str, Any], name: str = None) -> Dict[str, Any]: """ Start a Step Functions execution. Args: state_machine_arn: ARN of the state machine input_data: Input data for the execution name: Optional execution name Returns: Execution ARN and start date """ try: result = sfn_client.start_execution(state_machine_arn, input_data, name) if "error" in result: return result return { "status": "success", "execution": result } except Exception as e: return {"status": "error", "message": str(e)} def describe_sfn_execution(execution_arn: str) -> Dict[str, Any]: """ Get details about a Step Functions execution. Args: execution_arn: ARN of the execution Returns: Execution status and details """ try: result = sfn_client.describe_execution(execution_arn) if "error" in result: return result return { "status": "success", "execution": result } except Exception as e: return {"status": "error", "message": str(e)} def list_sfn_state_machines() -> Dict[str, Any]: """ List all Step Functions state machines. Returns: List of state machines """ try: machines = sfn_client.list_state_machines() if isinstance(machines, dict) and "error" in machines: return machines return { "status": "success", "count": len(machines), "machines": machines } except Exception as e: return {"status": "error", "message": str(e)} def get_sfn_execution_history(execution_arn: str) -> Dict[str, Any]: """ Get execution history for a Step Functions execution. Args: execution_arn: ARN of the execution Returns: List of execution events """ try: events = sfn_client.get_execution_history(execution_arn) if isinstance(events, dict) and "error" in events: return events return { "status": "success", "count": len(events), "events": events } except Exception as e: return {"status": "error", "message": str(e)} def list_s3_buckets() -> Dict[str, Any]: """ List all S3 buckets. Returns: List of S3 buckets """ try: buckets = s3_client.list_buckets() if isinstance(buckets, dict) and "error" in buckets: return buckets return { "status": "success", "count": len(buckets), "buckets": buckets } except Exception as e: return {"status": "error", "message": str(e)} def list_s3_objects(bucket: str, prefix: str = "", max_keys: int = 100) -> Dict[str, Any]: """ List objects in an S3 bucket. Args: bucket: Bucket name prefix: Optional prefix to filter objects max_keys: Maximum number of objects to return Returns: List of objects in the bucket """ try: result = s3_client.list_objects(bucket, prefix, max_keys) if "error" in result: return result return { "status": "success", "result": result } except Exception as e: return {"status": "error", "message": str(e)} def get_s3_object(bucket: str, key: str) -> Dict[str, Any]: """ Get an object from S3. Args: bucket: Bucket name key: Object key Returns: Object data """ try: result = s3_client.get_object(bucket, key) if "error" in result: return result return { "status": "success", "object": result } except Exception as e: return {"status": "error", "message": str(e)} def get_s3_bucket_size(bucket: str) -> Dict[str, Any]: """ Get total size of objects in an S3 bucket. Args: bucket: Bucket name Returns: Bucket size statistics """ try: result = s3_client.get_bucket_size(bucket) if "error" in result: return result return { "status": "success", "result": result } except Exception as e: return {"status": "error", "message": str(e)}