Scheduled Lambda functions — triggered by EventBridge rules on a cron schedule — can fail silently. Throttling, deployment errors, or permission issues can prevent execution without obvious notification. An Alert24 heartbeat check catches this automatically.
Before you start
- In Alert24, go to Monitoring → Add check → Heartbeat
- Name it after your Lambda (e.g., "Data export Lambda")
- Set Expected interval to match your EventBridge schedule
- Set Grace period to at least 60 seconds (Lambda cold start + execution time)
- Save and store the token in AWS Secrets Manager or SSM Parameter Store
Add the ping to your Lambda handler
import urllib.request
import os
HEARTBEAT_URL = f"https://app.alert24.net/api/hb/{os.environ['ALERT24_HB_TOKEN']}"
def lambda_handler(event, context):
# Your existing logic
process_data()
generate_report()
upload_to_s3()
# Ping Alert24 on success (only reached if no exception above)
urllib.request.urlopen(HEARTBEAT_URL, timeout=5)
return {'statusCode': 200}
// Node.js
const https = require('https');
exports.handler = async (event) => {
// Your existing logic
await processData();
await generateReport();
// Ping Alert24 on success
await new Promise((resolve, reject) => {
const req = https.get(
`https://app.alert24.net/api/hb/${process.env.ALERT24_HB_TOKEN}`,
(res) => resolve(res)
);
req.on('error', reject);
req.setTimeout(5000, () => req.destroy());
});
return { statusCode: 200 };
};
Store the token as an environment variable
In your Lambda configuration, add an environment variable:
ALERT24_HB_TOKEN = YOUR_TOKEN
Or retrieve it from Secrets Manager at cold start:
import boto3, json
_token = None
def get_token():
global _token
if not _token:
client = boto3.client('secretsmanager')
secret = client.get_secret_value(SecretId='alert24/heartbeat-token')
_token = json.loads(secret['SecretString'])['token']
return _token
Lambda function URL or EventBridge target
The heartbeat fires from within your Lambda — no changes to your EventBridge rule or trigger configuration are needed. Alert24 detects missed heartbeats based on time since last ping, regardless of how Lambda is invoked.
Tips
- Timeout setting: The Lambda itself has a timeout configured in AWS. Make sure the heartbeat curl/urllib call is included in your timeout budget — it typically completes in under 100ms.
- Exception handling: Don't catch exceptions before the heartbeat ping. If your business logic throws, the ping never fires — which is exactly what you want. Alert24 creates an incident after the grace period.
- Retries: EventBridge retries failed Lambda invocations (up to 2 times by default). The heartbeat only fires when a successful invocation completes, so retries don't cause duplicate pings.
- Dead letter queues: Combine heartbeat monitoring with a DLQ on your Lambda for two-layer visibility: Alert24 catches missed heartbeats (silent failure), DLQ captures exception payloads for debugging.