compare_lambda_performance
Analyze and compare AWS Lambda function performance metrics including duration, cold starts, errors, invocations, and costs across specified time ranges to identify optimization opportunities.
Instructions
Compare performance metrics between multiple Lambda functions
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| functionNames | Yes | List of Lambda function names to compare | |
| timeRange | No | Time range for comparison (default: 24h) | |
| metrics | No | Metrics to compare (default: all) |
Implementation Reference
- index.js:353-378 (handler)The main handler function for the 'compare_lambda_performance' tool. Parses input arguments, delegates comparison logic to LambdaAnalyzer.compareFunctions, formats the results including a markdown table, insights, and recommendations into a text response.async compareLambdaPerformance(args) { const { functionNames, timeRange = '24h', metrics = ['duration', 'cold-starts', 'errors', 'invocations', 'cost'] } = args; const comparison = await this.lambdaAnalyzer.compareFunctions( functionNames, timeRange, metrics ); return { content: [ { type: 'text', text: `# Lambda Performance Comparison\n\n` + `## Functions Analyzed\n` + `${functionNames.map(name => `- ${name}`).join('\n')}\n\n` + `## Performance Comparison\n` + `${this.formatComparisonTable(comparison)}\n\n` + `## Key Insights\n` + `${comparison.insights.map(insight => `- ${insight}`).join('\n')}\n\n` + `## Recommendations\n` + `${comparison.recommendations.map(rec => `- ${rec}`).join('\n')}` } ] }; }
- index.js:102-129 (schema)Input schema definition for the 'compare_lambda_performance' tool, specifying required functionNames array and optional timeRange and metrics parameters.{ name: 'compare_lambda_performance', description: 'Compare performance metrics between multiple Lambda functions', inputSchema: { type: 'object', properties: { functionNames: { type: 'array', items: { type: 'string' }, description: 'List of Lambda function names to compare' }, timeRange: { type: 'string', enum: ['1h', '6h', '24h', '7d'], description: 'Time range for comparison (default: 24h)' }, metrics: { type: 'array', items: { type: 'string', enum: ['duration', 'cold-starts', 'errors', 'invocations', 'cost'] }, description: 'Metrics to compare (default: all)' } }, required: ['functionNames'] } },
- src/lambda-analyzer.js:99-125 (helper)Core comparison utility that analyzes performance metrics for each specified Lambda function using analyzeFunction, extracts relevant metric values, generates insights and recommendations, and returns structured comparison data used by the tool handler.async compareFunctions(functionNames, timeRange, metrics) { const comparisons = []; for (const functionName of functionNames) { const analysis = await this.analyzeFunction(functionName, timeRange, false); comparisons.push({ name: functionName, values: { duration: analysis.avgDuration, 'cold-starts': analysis.coldStartRate, errors: analysis.errorRate, invocations: analysis.totalInvocations, cost: await this.estimateCost(analysis) } }); } const insights = this.generateComparisonInsights(comparisons); const recommendations = this.generateComparisonRecommendations(comparisons); return { functions: comparisons, metrics, insights, recommendations }; }
- index.js:220-221 (registration)Dispatch registration in the CallToolRequest handler switch statement, mapping the tool name to the compareLambdaPerformance handler.case 'compare_lambda_performance': return await this.compareLambdaPerformance(args);
- index.js:521-531 (helper)Helper function to format comparison data into a markdown table, used in the tool handler response.formatComparisonTable(comparison) { const headers = ['Function', ...comparison.metrics]; const rows = comparison.functions.map(func => [ func.name, ...comparison.metrics.map(metric => func.values[metric]) ]); return `| ${headers.join(' | ')} |\n` + `| ${headers.map(() => '---').join(' | ')} |\n` + rows.map(row => `| ${row.join(' | ')} |`).join('\n'); }