track_cold_starts
Analyze AWS Lambda cold start patterns to identify performance bottlenecks and optimize function initialization times. Specify a function name and time range to track cold start occurrences and durations.
Instructions
Track and analyze cold start patterns for Lambda functions
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| functionName | Yes | Name of the Lambda function | |
| timeRange | No | Time range for cold start analysis (default: 24h) |
Implementation Reference
- index.js:64-82 (registration)Registration of the track_cold_starts tool in the ListTools response, including name, description, and input schema{ name: 'track_cold_starts', description: 'Track and analyze cold start patterns for Lambda functions', inputSchema: { type: 'object', properties: { functionName: { type: 'string', description: 'Name of the Lambda function' }, timeRange: { type: 'string', enum: ['1h', '6h', '24h', '7d'], description: 'Time range for cold start analysis (default: 24h)' } }, required: ['functionName'] } },
- index.js:67-81 (schema)Input schema definition for track_cold_starts tool parametersinputSchema: { type: 'object', properties: { functionName: { type: 'string', description: 'Name of the Lambda function' }, timeRange: { type: 'string', enum: ['1h', '6h', '24h', '7d'], description: 'Time range for cold start analysis (default: 24h)' } }, required: ['functionName'] }
- index.js:286-315 (handler)Tool handler method that processes tool arguments, delegates to ColdStartTracker for analysis, formats the markdown response, and returns itasync trackColdStarts(args) { const { functionName, timeRange = '24h' } = args; const coldStartData = await this.coldStartTracker.trackColdStarts( functionName, timeRange ); return { content: [ { type: 'text', text: `# Cold Start Analysis: ${functionName}\n\n` + `## Cold Start Statistics\n` + `- **Total Cold Starts**: ${coldStartData.total}\n` + `- **Cold Start Rate**: ${coldStartData.rate}%\n` + `- **Average Cold Start Duration**: ${coldStartData.avgDuration}ms\n` + `- **Longest Cold Start**: ${coldStartData.maxDuration}ms\n\n` + `## Cold Start Patterns\n` + `- **Peak Hours**: ${coldStartData.peakHours.join(', ')}\n` + `- **Frequency**: ${coldStartData.frequency}\n` + `- **Triggers**: ${coldStartData.triggers.join(', ')}\n\n` + `## Optimization Opportunities\n` + `${coldStartData.recommendations.map(rec => `- ${rec}`).join('\n')}\n\n` + `## Timeline\n` + `${this.formatColdStartTimeline(coldStartData.timeline)}` } ] }; }
- src/cold-start-tracker.js:14-49 (helper)Core helper function in ColdStartTracker that fetches cold start events from CloudWatch Logs, performs analysis on patterns, statistics, and generates recommendationsasync trackColdStarts(functionName, timeRange) { const timeRangeMs = this.parseTimeRange(timeRange); const endTime = new Date(); const startTime = new Date(endTime.getTime() - timeRangeMs); const logGroupName = `/aws/lambda/${functionName}`; try { // Get cold start events const coldStartEvents = await this.getColdStartEvents(logGroupName, startTime, endTime); // Get all invocation events for comparison const allInvocations = await this.getAllInvocations(logGroupName, startTime, endTime); // Analyze patterns const analysis = this.analyzeColdStartPatterns(coldStartEvents, allInvocations, timeRange); return { total: coldStartEvents.length, rate: this.calculateColdStartRate(coldStartEvents.length, allInvocations.length), avgDuration: analysis.avgDuration, maxDuration: analysis.maxDuration, minDuration: analysis.minDuration, peakHours: analysis.peakHours, frequency: analysis.frequency, triggers: analysis.triggers, recommendations: this.generateRecommendations(analysis), timeline: this.createTimeline(coldStartEvents, timeRange), patterns: analysis.patterns, statistics: analysis.statistics }; } catch (error) { console.error('Error tracking cold starts:', error); return this.getEmptyResult(); } }