62
62
ACTIONS = {
63
63
"get_ecs_troubleshooting_guidance" : {
64
64
"func" : get_ecs_troubleshooting_guidance ,
65
- "required_params" : ["app_name" ],
66
- "optional_params" : ["symptoms_description" ],
67
- "transformer" : lambda app_name , params : {
68
- "app_name" : app_name ,
65
+ "required_params" : ["ecs_cluster_name" ],
66
+ "optional_params" : ["ecs_service_name" , "symptoms_description" ],
67
+ "transformer" : lambda params : {
68
+ "cluster_name" : params ["ecs_cluster_name" ],
69
+ "service_name" : params .get ("ecs_service_name" ),
69
70
"symptoms_description" : params .get ("symptoms_description" ),
70
71
},
71
72
"description" : "Initial assessment and data collection" ,
72
73
"param_descriptions" : {
73
- "app_name" : "The name of the application/stack to troubleshoot" ,
74
- "symptoms_description" : "Description of symptoms experienced by the user" ,
74
+ "ecs_cluster_name" : "The name of the ECS Cluster to troubleshoot" ,
75
+ "ecs_service_name" : "The name of the ECS Service to troubleshoot (optional)" ,
76
+ "symptoms_description" : "Description of symptoms experienced by the uhser" ,
75
77
},
76
78
"example" : (
77
79
'action="get_ecs_troubleshooting_guidance", '
78
- 'parameters={"symptoms_description": "ALB returning 503 errors"}'
80
+ 'parameters={"ecs_cluster_name": "my-cluster", "ecs_service_name": "my-service", '
81
+ '"symptoms_description": "ALB returning 503 errors"}'
79
82
),
80
83
},
81
84
"fetch_cloudformation_status" : {
82
85
"func" : fetch_cloudformation_status ,
83
- "required_params" : ["stack_id " ],
86
+ "required_params" : ["cfn_stack_name " ],
84
87
"optional_params" : [],
85
- "transformer" : lambda app_name , params : {"stack_id" : params .get ("stack_id" , app_name )},
86
- "description" : "Infrastructure-level diagnostics for CloudFormation stacks" ,
87
- "param_descriptions" : {"stack_id" : "The CloudFormation stack identifier to analyze" },
88
- "example" : 'action="fetch_cloudformation_status", parameters={"stack_id": "my-app-stack"}' ,
88
+ "transformer" : lambda params : {"stack_id" : params .get ("cfn_stack_name" )},
89
+ "description" : "Infrastructure-level diagnostics for CloudFormation Stacks" ,
90
+ "param_descriptions" : {"cfn_stack_name" : "The CloudFormation Stack identifier to analyze" },
91
+ "example" : (
92
+ 'action="fetch_cloudformation_status", parameters={"cfn_stack_name": "my-app-stack"}'
93
+ ),
89
94
},
90
95
"fetch_service_events" : {
91
96
"func" : fetch_service_events ,
92
- "required_params" : ["app_name " , "cluster_name" , "service_name " ],
97
+ "required_params" : ["ecs_cluster_name " , "ecs_service_name " ],
93
98
"optional_params" : ["time_window" , "start_time" , "end_time" ],
94
- "transformer" : lambda app_name , params : {
95
- "app_name" : app_name ,
96
- "cluster_name" : params ["cluster_name" ],
97
- "service_name" : params ["service_name" ],
99
+ "transformer" : lambda params : {
100
+ "cluster_name" : params ["ecs_cluster_name" ],
101
+ "service_name" : params ["ecs_service_name" ],
98
102
"time_window" : params .get ("time_window" , 3600 ),
99
103
"start_time" : params .get ("start_time" ),
100
104
"end_time" : params .get ("end_time" ),
101
105
},
102
- "description" : "Service-level diagnostics for ECS services " ,
106
+ "description" : "Service-level diagnostics for ECS Services " ,
103
107
"param_descriptions" : {
104
- "app_name" : "The name of the application to analyze" ,
105
- "cluster_name" : "The name of the ECS cluster" ,
106
- "service_name" : "The name of the ECS service to analyze" ,
108
+ "ecs_cluster_name" : "The name of the ECS Cluster" ,
109
+ "ecs_service_name" : "The name of the ECS Service to analyze" ,
107
110
"time_window" : "Time window in seconds to look back for events (default: 3600)" ,
108
111
"start_time" : (
109
112
"Explicit start time for the analysis window "
116
119
},
117
120
"example" : (
118
121
'action="fetch_service_events", '
119
- 'parameters={"cluster_name ": "my-cluster", "service_name ": "my-service", '
122
+ 'parameters={"ecs_cluster_name ": "my-cluster", "ecs_service_name ": "my-service", '
120
123
'"time_window": 7200}'
121
124
),
122
125
},
123
126
"fetch_task_failures" : {
124
127
"func" : fetch_task_failures ,
125
- "required_params" : ["app_name" , "cluster_name " ],
128
+ "required_params" : ["ecs_cluster_name " ],
126
129
"optional_params" : ["time_window" , "start_time" , "end_time" ],
127
- "transformer" : lambda app_name , params : {
128
- "app_name" : app_name ,
129
- "cluster_name" : params ["cluster_name" ],
130
+ "transformer" : lambda params : {
131
+ "cluster_name" : params ["ecs_cluster_name" ],
130
132
"time_window" : params .get ("time_window" , 3600 ),
131
133
"start_time" : params .get ("start_time" ),
132
134
"end_time" : params .get ("end_time" ),
133
135
},
134
- "description" : "Task-level diagnostics for ECS task failures" ,
136
+ "description" : "Task-level diagnostics for ECS Task failures" ,
135
137
"param_descriptions" : {
136
- "app_name" : "The name of the application to analyze" ,
137
- "cluster_name" : "The name of the ECS cluster" ,
138
+ "ecs_cluster_name" : "The name of the ECS Cluster" ,
138
139
"time_window" : "Time window in seconds to look back for failures (default: 3600)" ,
139
140
"start_time" : (
140
141
"Explicit start time for the analysis window "
147
148
},
148
149
"example" : (
149
150
'action="fetch_task_failures", '
150
- 'parameters={"cluster_name ": "my-cluster", "time_window": 3600}'
151
+ 'parameters={"ecs_cluster_name ": "my-cluster", "time_window": 3600}'
151
152
),
152
153
},
153
154
"fetch_task_logs" : {
154
155
"func" : fetch_task_logs ,
155
- "required_params" : ["app_name" , "cluster_name" ],
156
- "optional_params" : ["task_id" , "time_window" , "filter_pattern" , "start_time" , "end_time" ],
157
- "transformer" : lambda app_name , params : {
158
- "app_name" : app_name ,
159
- "cluster_name" : params ["cluster_name" ],
160
- "task_id" : params .get ("task_id" ),
156
+ "required_params" : ["ecs_cluster_name" ],
157
+ "optional_params" : [
158
+ "ecs_task_id" ,
159
+ "time_window" ,
160
+ "filter_pattern" ,
161
+ "start_time" ,
162
+ "end_time" ,
163
+ ],
164
+ "transformer" : lambda params : {
165
+ "cluster_name" : params ["ecs_cluster_name" ],
166
+ "task_id" : params .get ("ecs_task_id" ),
161
167
"time_window" : params .get ("time_window" , 3600 ),
162
168
"filter_pattern" : params .get ("filter_pattern" ),
163
169
"start_time" : params .get ("start_time" ),
164
170
"end_time" : params .get ("end_time" ),
165
171
},
166
- "description" : "Application-level diagnostics through CloudWatch logs " ,
172
+ "description" : "Application-level diagnostics through CloudWatch Logs " ,
167
173
"param_descriptions" : {
168
- "app_name" : "The name of the application to analyze" ,
169
- "cluster_name" : "The name of the ECS cluster" ,
170
- "task_id" : "Specific task ID to retrieve logs for" ,
174
+ "ecs_cluster_name" : "The name of the ECS Cluster" ,
175
+ "ecs_task_id" : "Specific ECS Task ID to retrieve logs for" ,
171
176
"time_window" : "Time window in seconds to look back for logs (default: 3600)" ,
172
- "filter_pattern" : "CloudWatch logs filter pattern" ,
177
+ "filter_pattern" : "CloudWatch Logs filter pattern" ,
173
178
"start_time" : (
174
179
"Explicit start time for the analysis window "
175
180
"(UTC, takes precedence over time_window if provided)"
181
186
},
182
187
"example" : (
183
188
'action="fetch_task_logs", '
184
- 'parameters={"cluster_name ": "my-cluster", "filter_pattern": "ERROR", '
189
+ 'parameters={"ecs_cluster_name ": "my-cluster", "filter_pattern": "ERROR", '
185
190
'"time_window": 1800}'
186
191
),
187
192
},
188
193
"detect_image_pull_failures" : {
189
194
"func" : detect_image_pull_failures ,
190
- "required_params" : ["app_name" ],
191
- "optional_params" : [],
192
- "transformer" : lambda app_name , params : {"app_name" : app_name },
195
+ "required_params" : [], # No single required param, but need at least one combo
196
+ "optional_params" : [
197
+ "ecs_cluster_name" ,
198
+ "ecs_service_name" ,
199
+ "cfn_stack_name" ,
200
+ "family_prefix" ,
201
+ "ecs_task_id" ,
202
+ ],
203
+ "transformer" : lambda params : {
204
+ "cluster_name" : params .get ("ecs_cluster_name" ),
205
+ "service_name" : params .get ("ecs_service_name" ),
206
+ "stack_name" : params .get ("cfn_stack_name" ),
207
+ "family_prefix" : params .get ("family_prefix" ),
208
+ "task_id" : params .get ("ecs_task_id" ),
209
+ },
193
210
"description" : "Specialized tool for detecting container image pull failures" ,
194
- "param_descriptions" : {"app_name" : "Application name to check for image pull failures" },
195
- "example" : 'action="detect_image_pull_failures", parameters={}' ,
211
+ "param_descriptions" : {
212
+ "ecs_cluster_name" : (
213
+ "Name of the ECS Cluster (required if ecs_service_name/ecs_task_id provided)"
214
+ ),
215
+ "ecs_service_name" : "Name of the ECS Service (requires ecs_cluster_name)" ,
216
+ "cfn_stack_name" : "Name of the CloudFormation Stack to find related Task Definitions" ,
217
+ "family_prefix" : "Prefix to filter Task Definition families (e.g., 'my-app')" ,
218
+ "ecs_task_id" : (
219
+ "ID of an ECS Task to get its Task Definition (requires ecs_cluster_name)"
220
+ ),
221
+ },
222
+ "example" : (
223
+ 'action="detect_image_pull_failures", '
224
+ 'parameters={"ecs_cluster_name": "my-cluster", "ecs_service_name": "my-service"}'
225
+ ),
196
226
},
197
227
"fetch_network_configuration" : {
198
228
"func" : fetch_network_configuration ,
199
- "required_params" : ["app_name " ],
200
- "optional_params" : ["vpc_id" , "cluster_name" ],
201
- "transformer" : lambda app_name , params : {
202
- "app_name " : app_name ,
229
+ "required_params" : ["ecs_cluster_name " ],
230
+ "optional_params" : ["vpc_id" ],
231
+ "transformer" : lambda params : {
232
+ "cluster_name " : params [ "ecs_cluster_name" ] ,
203
233
"vpc_id" : params .get ("vpc_id" ),
204
- "cluster_name" : params .get ("cluster_name" ),
205
234
},
206
235
"description" : "Network-level diagnostics for ECS deployments" ,
207
236
"param_descriptions" : {
208
- "app_name" : "The name of the application to analyze" ,
209
- "vpc_id" : "Specific VPC ID to analyze" ,
210
- "cluster_name" : "Specific ECS cluster name" ,
237
+ "ecs_cluster_name" : "Name of the ECS Cluster to analyze" ,
238
+ "vpc_id" : "Specific VPC ID to analyze (optional)" ,
211
239
},
212
240
"example" : (
213
241
'action="fetch_network_configuration", '
214
- 'parameters={"vpc_id ": "vpc-12345678 ", '
215
- '"cluster_name ": "my-cluster "}'
242
+ 'parameters={"ecs_cluster_name ": "my-cluster ", '
243
+ '"vpc_id ": "vpc-12345678 "}'
216
244
),
217
245
},
218
246
}
@@ -284,7 +312,6 @@ def generate_troubleshooting_docs():
284
312
doc_footer = """```
285
313
286
314
Parameters:
287
- app_name: Application/stack name (required for most actions)
288
315
action: The troubleshooting action to perform (see available actions above)
289
316
parameters: Action-specific parameters (see parameter specifications above)
290
317
@@ -311,17 +338,29 @@ def _validate_action(action: str) -> None:
311
338
raise ValueError (f"Invalid action '{ action } '. Valid actions: { valid_actions } " )
312
339
313
340
314
- def _validate_parameters (action : str , app_name : Optional [ str ], parameters : Dict [str , Any ]) -> None :
341
+ def _validate_parameters (action : str , parameters : Dict [str , Any ]) -> None :
315
342
"""Validate required parameters for the given action."""
316
343
required = ACTIONS [action ]["required_params" ]
317
344
318
- # Check app_name if required
319
- if "app_name" in required and (not app_name or not app_name .strip ()):
320
- raise ValueError (f"app_name is required for action '{ action } '" )
321
-
322
- # Check other required parameters
345
+ # Special case for detect_image_pull_failures which needs at least one of several combinations
346
+ if action == "detect_image_pull_failures" :
347
+ if not any (
348
+ [
349
+ (parameters .get ("ecs_cluster_name" ) and parameters .get ("ecs_service_name" )),
350
+ (parameters .get ("ecs_cluster_name" ) and parameters .get ("ecs_task_id" )),
351
+ parameters .get ("cfn_stack_name" ),
352
+ parameters .get ("family_prefix" ),
353
+ ]
354
+ ):
355
+ raise ValueError (
356
+ "At least one of: ecs_cluster_name+ecs_service_name, ecs_cluster_name+ecs_task_id, "
357
+ "cfn_stack_name, or family_prefix must be provided for 'detect_image_pull_failures'"
358
+ )
359
+ return
360
+
361
+ # Check required parameters
323
362
for param in required :
324
- if param != "app_name" and param not in parameters :
363
+ if param not in parameters :
325
364
raise ValueError (f"Missing required parameter '{ param } ' for action '{ action } '" )
326
365
327
366
@@ -330,7 +369,6 @@ def _validate_parameters(action: str, app_name: Optional[str], parameters: Dict[
330
369
331
370
332
371
async def ecs_troubleshooting_tool (
333
- app_name : Optional [str ] = None ,
334
372
action : TroubleshootingAction = "get_ecs_troubleshooting_guidance" ,
335
373
parameters : Optional [Dict [str , Any ]] = None ,
336
374
) -> Dict [str , Any ]:
@@ -342,7 +380,6 @@ async def ecs_troubleshooting_tool(
342
380
to perform.
343
381
344
382
Args:
345
- app_name: Application/stack name (required for most actions)
346
383
action: The troubleshooting action to perform
347
384
parameters: Action-specific parameters
348
385
@@ -383,13 +420,13 @@ async def ecs_troubleshooting_tool(
383
420
}
384
421
385
422
# Validate parameters
386
- _validate_parameters (action , app_name , parameters )
423
+ _validate_parameters (action , parameters )
387
424
388
425
# Get action configuration
389
426
action_config = ACTIONS [action ]
390
427
391
428
# Transform parameters using action-specific transformer
392
- func_params = action_config ["transformer" ](app_name , parameters )
429
+ func_params = action_config ["transformer" ](parameters )
393
430
394
431
# Call the function and await it if it's a coroutine
395
432
result = action_config ["func" ](** func_params )
0 commit comments