Set up serverless cron jobs and scheduled functions
✓Works with OpenClaudeYou are a serverless architect. The user wants to set up serverless cron jobs and scheduled functions using AWS Lambda and EventBridge.
What to check first
- Run
aws lambda list-functionsto verify AWS Lambda is accessible and configured - Check your AWS IAM user has
lambda:InvokeFunction,events:PutRule, andevents:PutTargetspermissions - Verify Node.js runtime is available locally with
node --version
Steps
- Create an IAM execution role for Lambda with trust policy for
lambda.amazonaws.comand attachAWSLambdaBasicExecutionRole - Write your Lambda handler function in Node.js that will execute on schedule
- Zip the handler code and dependencies into a deployment package
- Create the Lambda function using
aws lambda create-functionwith your IAM role ARN - Create an EventBridge rule using
aws events put-rulewith--schedule-expressionin cron format (e.g.,cron(0 9 * * ? *)for 9 AM daily) - Add the Lambda function as a target to the EventBridge rule using
aws events put-targets - Grant EventBridge permission to invoke your Lambda with
aws lambda add-permission - Test the rule by manually triggering with
aws lambda invokeor wait for the scheduled time
Code
// handler.js - Lambda function that runs on schedule
exports.handler = async (event) => {
console.log('Scheduled job triggered at:', new Date().toISOString());
console.log('Event source:', event.source);
// Your cron job logic here
try {
// Example: cleanup task
const result = await performScheduledTask();
return {
statusCode: 200,
body: JSON.stringify({
message: 'Cron job completed successfully',
data: result,
timestamp: new Date().toISOString()
})
};
} catch (error) {
console.error('Error in scheduled job:', error);
throw error;
}
};
async function performScheduledTask() {
// Simulate async work: fetch data, process, cleanup, etc.
return new Promise((resolve) => {
setTimeout(() => {
resolve({ itemsProcessed: 42 });
}, 1000);
});
}
#!/bin/bash
# deploy-cron.sh - Complete deployment script
# 1. Create execution role
ROLE_ARN=$(aws iam create-role \
--role-name lambda-cron-role \
--assume-role-policy-document '{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {"Service": "lambda.amazonaws.com"},
"Action": "sts:AssumeRole"
}]
}'
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Serverless Skills
Other Claude Code skills in the same category — free to download.
Vercel Deploy
Deploy and configure applications on Vercel
Netlify Deploy
Deploy and configure applications on Netlify
SST Setup
Set up SST (Serverless Stack) for full-stack serverless apps
Serverless Framework
Configure Serverless Framework for multi-cloud deployment
Edge Functions
Build and deploy edge functions (Vercel, Cloudflare Workers)
Serverless Database
Set up serverless databases (PlanetScale, Neon, Turso)
Serverless Queue
Implement serverless queues and event-driven processing
Want a Serverless skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.