rri-lambda-analyzer
v1.0.8
Published
A comprehensive toolkit for analyzing AWS Lambda functions - get function details, logs, metrics, and perform security audits
Maintainers
Readme
AWS Lambda Analyzer
A comprehensive TypeScript/JavaScript toolkit for analyzing AWS Lambda functions. Get function details, logs, performance metrics, and perform security audits with ease.
Note: This library also includes an optional MCP (Model Context Protocol) server for integration with Claude and other AI tools.
Features
- 🔍 Function Analysis: Get detailed function information, code, and configuration
- 📊 Performance Metrics: Analyze execution time, memory usage, cold starts, and errors
- 🛡️ Security Auditing: Automated security checks and recommendations
- 📋 Log Analysis: Retrieve and analyze CloudWatch logs with filtering
- ⚡ Function Invocation: Test functions with custom payloads
- 🏗️ Layer Management: List and analyze Lambda layers
- 🔧 Batch Operations: Analyze multiple functions simultaneously
- 📈 Cost Analysis: Calculate approximate Lambda costs
- ✅ Configuration Validation: Validate function configurations
Before Installing, check out MCP Server Integration for one line installation to begin using this MCP from the Claude CLI
Installation
npm install rri-lambda-analyzerQuick Start
import { LambdaAnalyzer, analyzeLambdaFunction } from 'rri-lambda-analyzer';
// Initialize analyzer (uses AWS credentials from environment)
const analyzer = new LambdaAnalyzer();
// Get basic function information
const functions = await analyzer.listFunctions();
console.log('Functions:', functions);
// Analyze a specific function
const details = await analyzer.getFunctionDetails('my-function');
console.log('Function details:', details);
// Quick analysis with utility function
const analysis = await analyzeLambdaFunction('my-function');
console.log('Complete analysis:', analysis);Configuration
AWS Credentials
The library uses AWS SDK v3 and supports all standard AWS credential methods:
- Environment variables (
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_REGION) - AWS credentials file (
~/.aws/credentials) - IAM roles (for EC2/Lambda/ECS)
- AWS SSO
You can also provide credentials explicitly:
import { LambdaAnalyzer } from 'rri-lambda-analyzer';
const analyzer = new LambdaAnalyzer({
region: 'us-east-1',
accessKeyId: 'your-access-key',
secretAccessKey: 'your-secret-key'
});Required IAM Permissions
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"lambda:ListFunctions",
"lambda:GetFunction",
"lambda:InvokeFunction",
"lambda:ListLayers",
"logs:DescribeLogGroups",
"logs:FilterLogEvents"
],
"Resource": "*"
}
]
}API Reference
LambdaAnalyzer Class
The main class for analyzing Lambda functions.
import { LambdaAnalyzer } from 'rri-lambda-analyzer';
const analyzer = new LambdaAnalyzer(config?: AWSConfig);Methods
listFunctions(options?: ListFunctionsOptions): Promise<FunctionInfo[]>- List all functionsgetFunctionDetails(name: string, version?: string): Promise<FunctionCodeInfo>- Get function detailsgetFunctionLogs(name: string, options?: LogOptions): Promise<LogEvent[]>- Get function logsinvokeFunction(name: string, payload?: any, options?: InvokeOptions): Promise<InvokeFunctionResult>- Invoke functionanalyzeFunctionPerformance(name: string, timeRange?: TimeRange): Promise<PerformanceMetrics>- Analyze performanceauditFunction(name: string): Promise<SecurityAuditResult>- Security auditcompareFunctionVersions(name: string, versions: string[]): Promise<ComparisonResult>- Compare versions
Utility Functions
import {
analyzeLambdaFunction,
getLambdaMetrics,
validateLambdaConfig,
batchAnalyzeFunctions,
findFunctionsByRuntime,
findOversizedFunctions,
findFunctionsWithErrors
} from 'rri-lambda-analyzer';Examples
Performance Monitoring
const analyzer = new LambdaAnalyzer();
const performance = await analyzer.analyzeFunctionPerformance('my-function');
console.log(`Invocations: ${performance.invocationCount}`);
console.log(`Errors: ${performance.errorCount}`);
console.log(`Average Duration: ${performance.averageDuration}ms`);
console.log(`Cold Starts: ${performance.coldStarts}`);Security Audit
const audit = await analyzer.auditFunction('my-function');
console.log(`Risk Score: ${audit.riskScore}/100`);
audit.findings
.filter(f => f.severity === 'HIGH')
.forEach(finding => {
console.log(`- ${finding.title}: ${finding.description}`);
});Batch Analysis
import { batchAnalyzeFunctions, findFunctionsByRuntime } from 'rri-lambda-analyzer';
// Analyze multiple functions
const analyses = await batchAnalyzeFunctions(['func1', 'func2', 'func3']);
// Find functions by runtime
const pythonFunctions = await findFunctionsByRuntime('python3.9');MCP Server Integration
This library also includes an MCP server for Claude integration. There are three ways to use it:
Method 1: Claude CLI Installation (Recommended)
Use the Claude CLI to install and configure the MCP server automatically:
# Install using Claude CLI (requires Claude CLI to be installed)
npm install -g rri-lambda-analyzer && claude mcp add rri-lambda-analyzer rri-lambda-analyzerThis method will:
- Automatically install the package from npm
- Add the MCP server configuration to your Claude CLI settings
- Handle the setup for you without manual configuration
Region Selection: When using the MCP server with Claude CLI, you can dynamically change the AWS region during your session by asking Claude to use the set_region tool:
Use the set_region tool to change the AWS region to us-west-2The MCP server will switch to the new region and all subsequent Lambda operations will use that region.
All methods will start the MCP server and make all Lambda analysis tools available to Claude as native capabilities.
Method 2: Direct NPM Installation
Install globally and run as a subprocess:
# Install globally
npm install -g rri-lambda-analyzer
# Run as MCP server
rri-lambda-analyzerAdd to Claude Desktop configuration:
{
"mcpServers": {
"lambda-analyzer": {
"command": "rri-lambda-analyzer",
"env": {
"AWS_REGION": "us-east-1",
"AWS_PROFILE": "your-profile"
}
}
}
}Method 3: Using npx
Run directly with npx without global installation:
# Run as MCP server
npx rri-lambda-analyzerAdd to Claude Desktop configuration:
{
"mcpServers": {
"lambda-analyzer": {
"command": "npx",
"args": ["rri-lambda-analyzer"],
"env": {
"AWS_REGION": "us-east-1",
"AWS_PROFILE": "your-profile"
}
}
}
}Available MCP Tools
When using the MCP server, Claude has access to these tools:
- set_region: Change the AWS region for all Lambda operations
- list_functions: List AWS Lambda functions in the current region
- get_function_code: Get function code and configuration details
- get_function_logs: Retrieve CloudWatch logs for a function
- invoke_function: Invoke a function with custom payloads
- list_layers: List available Lambda layers
Installing Claude CLI
To install the Claude Code CLI, you can follow these steps:
Install Node.js and npm. Claude Code requires npm and Node.js version 18 or higher.
Run the following command to install Claude Code globally:
npm install -g @anthropic-ai/claude-code This command installs the Claude Code CLI on your system.
- Launch Claude Code by running:
claude
- Follow the prompts to generate and use an API key from Anthropic console
These steps will get you started with Claude Code CLI, allowing you to start coding with AI in your terminal.
If you encounter any issues during the installation, you can refer to the official documentation for more detailed instructions
https://docs.anthropic.com/en/docs/claude-code/overview
TypeScript Support
Full TypeScript support with exported types:
import {
FunctionInfo,
PerformanceMetrics,
SecurityAuditResult,
AWSConfig
} from 'rri-lambda-analyzer';Error Handling
All methods include comprehensive error handling:
try {
const details = await analyzer.getFunctionDetails('my-function');
} catch (error) {
console.error('Failed to get function details:', error.message);
}Contributing
Contributions are welcome! Please read our contributing guidelines and submit pull requests to our repository.
License
MIT License - see LICENSE file for details.
