compare_lambda_performance
Analyze and compare AWS Lambda function performance by evaluating metrics such as duration, cold starts, errors, invocations, and costs across specified time ranges to optimize efficiency and reduce expenses.
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 | |
| metrics | No | Metrics to compare (default: all) | |
| timeRange | No | Time range for comparison (default: 24h) |
Implementation Reference
- index.js:353-378 (handler)Main MCP tool handler that parses arguments, calls LambdaAnalyzer.compareFunctions, and formats the comparison response as markdown.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, returned by ListTools handler.{ 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'] } },
- index.js:220-221 (registration)Dispatch registration in the CallToolRequestSchema handler's switch statement.case 'compare_lambda_performance': return await this.compareLambdaPerformance(args);
- src/lambda-analyzer.js:99-125 (helper)Core helper method implementing the comparison logic by analyzing each Lambda function and compiling metrics, insights, and recommendations.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 }; }
- src/lambda-analyzer.js:549-565 (helper)Helper function to generate key insights from the comparison data.generateComparisonInsights(comparisons) { const insights = []; // Find best and worst performers const bestDuration = comparisons.reduce((best, current) => current.values.duration < best.values.duration ? current : best ); const worstColdStart = comparisons.reduce((worst, current) => current.values['cold-starts'] > worst.values['cold-starts'] ? current : worst ); insights.push(`${bestDuration.name} has the best average duration (${bestDuration.values.duration}ms)`); insights.push(`${worstColdStart.name} has the highest cold start rate (${worstColdStart.values['cold-starts']}%)`); return insights; }