AWS Lambda Function Monitoring with Vigilmon: Serverless Uptime and Health Checks
AWS Lambda functions are the backbone of serverless architectures — they power APIs, process events, run scheduled tasks, and handle webhooks. When Lambda functions fail, it's often silent: no server to check, no process to monitor. Vigilmon adds an external perspective by monitoring the HTTP interfaces your Lambda functions expose.
Why Lambda Functions Need External Monitoring
Lambda cold starts, concurrency limits, and IAM permission issues can cause failures that are invisible without external monitoring:
- Cold start timeouts: Functions taking longer than their configured timeout return errors
- Concurrency limits: Under high load, Lambda throttles requests
- Code deployment issues: A bad deploy can break an endpoint while CloudWatch shows no errors
- API Gateway issues: Your Lambda might be healthy while API Gateway returns 5xx errors
- VPC configuration: Lambda functions in VPCs can lose internet connectivity
External HTTP monitoring catches all of these from the user's perspective.
Setting Up Lambda Monitoring with Vigilmon
Monitor 1: API Gateway Endpoint Health
The most common pattern - monitor the URL your Lambda function handles:
URL: https://api.yourapp.com/health
Type: HTTP(s)
Interval: 1 minute
Assert: Status code 200
Assert: Response time < 3000ms
Implement a Health Check Function
Create a dedicated health check Lambda function:
`javascript
// handler.js
const AWS = require('aws-sdk');
exports.handler = async (event) => {
const checks = {};
// Check DynamoDB connectivity
try {
const dynamodb = new AWS.DynamoDB({ region: process.env.AWS_REGION });
await dynamodb.listTables({ Limit: 1 }).promise();
checks.dynamodb = 'healthy';
} catch (err) {
checks.dynamodb = 'unhealthy';
}
// Check S3 connectivity
try {
const s3 = new AWS.S3();
await s3.headBucket({ Bucket: process.env.S3_BUCKET }).promise();
checks.s3 = 'healthy';
} catch (err) {
checks.s3 = err.code === 'NoSuchBucket' ? 'unhealthy' : 'healthy'; // 403 = exists but no access
}
const allHealthy = !Object.values(checks).includes('unhealthy');
return {
statusCode: allHealthy ? 200 : 503,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
status: allHealthy ? 'healthy' : 'unhealthy',
checks,
region: process.env.AWS_REGION,
function: process.env.AWS_LAMBDA_FUNCTION_NAME,
timestamp: new Date().toISOString()
})
};
};
`
Deploy with API Gateway
`yaml
serverless.yml (Serverless Framework)
service: vigilmon-health-check
provider:
name: aws
runtime: nodejs20.x
region: us-east-1
functions:
health:
handler: handler.handler
events:
- http:
path: /health
method: get
iamRoleStatements:
- Effect: Allow
Action: dynamodb:ListTables
Resource: "*"
`
Python Lambda Health Check
`python
import boto3
import json
import os
from datetime import datetime
def handler(event, context):
checks = {}
# Check RDS connectivity via a test query
try:
import psycopg2
conn = psycopg2.connect(
host=os.environ['DB_HOST'],
database=os.environ['DB_NAME'],
user=os.environ['DB_USER'],
password=os.environ['DB_PASSWORD'],
connect_timeout=3
)
conn.close()
checks['rds'] = 'healthy'
except Exception as e:
checks['rds'] = 'unhealthy'
# Check SQS queue accessibility
try:
sqs = boto3.client('sqs')
sqs.get_queue_attributes(
QueueUrl=os.environ['SQS_QUEUE_URL'],
AttributeNames=['ApproximateNumberOfMessages']
)
checks['sqs'] = 'healthy'
except Exception as e:
checks['sqs'] = 'unhealthy'
all_healthy = all(v == 'healthy' for v in checks.values())
return {
'statusCode': 200 if all_healthy else 503,
'headers': {'Content-Type': 'application/json'},
'body': json.dumps({
'status': 'healthy' if all_healthy else 'unhealthy',
'checks': checks,
'timestamp': datetime.utcnow().isoformat()
})
}
`
Recommended Vigilmon Settings for Lambda
| Setting | Value | Reason |
|---|---|---|
| Check interval | 5 minutes | Lambda cold starts can take 1-3s |
| Confirmation failures | 2 | Avoid cold start false positives |
| Response timeout | 30s | Account for cold starts (up to 15s) |
| Alert on timeout | Yes | Timeout often means cold start issues |
| SSL monitoring | Yes | API Gateway certificates need monitoring |
Monitor Lambda Warming (Prevent Cold Starts)
Keep your Lambda warm with scheduled pings via Vigilmon. Set a 5-minute interval monitor on your health endpoint — this keeps at least one Lambda instance warm between real requests.
Monitoring Lambda SQS Consumers
For event-driven Lambda functions consuming from SQS, create a separate health endpoint that checks queue depth:
`javascript
exports.queueHealthHandler = async () => {
const sqs = new AWS.SQS();
const attrs = await sqs.getQueueAttributes({
QueueUrl: process.env.QUEUE_URL,
AttributeNames: ['ApproximateNumberOfMessages', 'ApproximateNumberOfMessagesNotVisible']
}).promise();
const depth = parseInt(attrs.Attributes.ApproximateNumberOfMessages);
const processing = parseInt(attrs.Attributes.ApproximateNumberOfMessagesNotVisible);
const healthy = depth < 1000; // Alert if queue is backing up
return {
statusCode: healthy ? 200 : 503,
body: JSON.stringify({ status: healthy ? 'healthy' : 'backlogged', depth, processing })
};
};
`
Start monitoring your AWS Lambda functions for free at Vigilmon - external health checks that CloudWatch can't provide.
Top comments (0)