Four Golden Signals for Lambda
1. Error Rate
javascript
exports.handler = async (event, context) => {
try {
return await processEvent(event);
} catch (err) {
console.error(JSON.stringify({ event: 'lambda_error', fn: context.functionName, error: err.message }));
throw err;
}
};
2. Cold Start Detection
`javascript
const isColdStart = !global._initialized;
if (!isColdStart) global._initialized = true;
console.log(JSON.stringify({ cold_start: isColdStart, fn: context.functionName }));
`
3. Timeout Warning
javascript
const warningTimeout = setTimeout(() => {
console.warn('approaching_timeout: ' + context.getRemainingTimeInMillis() + 'ms left');
}, context.getRemainingTimeInMillis() - 5000);
try {
return await doWork(event);
} finally {
clearTimeout(warningTimeout);
}
4. External HTTP Monitoring
For Lambda behind API Gateway, monitor the HTTP endpoint with Vigilmon:
javascript
exports.health = async () => ({ statusCode: 200, body: JSON.stringify({ status: 'ok' }) });
Set Vigilmon to check /health every minute and alert on status != 200.
CloudWatch Alarms Worth Setting
| Metric | Threshold |
|---|---|
| Errors | > 1% |
| Throttles | > 0 |
| Duration | > 80% of timeout |
Top comments (0)