This guide explains how to schedule Lambda function execution using EventBridge Rules. The Cron component allows you to run functions on a recurring schedule using rate or cron expressions.
Creating a scheduled task
The simplest way to create a scheduled task is to provide a name, schedule expression, and handler:
fromstelvio.aws.cronimportCron# Run every hourCron("hourly-cleanup","rate(1 hour)","tasks/cleanup.handler")# Run at 2 AM UTC dailyCron("nightly-report","cron(0 2 * * ? *)","tasks/report.handler")
Schedule expressions
Stelvio supports two types of schedule expressions:
Rate expressions
Use rate expressions for simple recurring schedules:
Use singular form (minute, hour, day) when value is 1, plural otherwise.
Cron expressions
Use cron expressions for more complex schedules:
# Every day at 9:30 AM UTCCron("morning-report","cron(30 9 * * ? *)","tasks/report.handler")# Every Monday at 8 AM UTCCron("weekly-digest","cron(0 8 ? * MON *)","tasks/digest.handler")# First day of each month at midnightCron("monthly-cleanup","cron(0 0 1 * ? *)","tasks/cleanup.handler")
fromstelvio.aws.functionimportFunctionprocessor=Function("data-processor",handler="tasks/process.handler",memory=2048)# Different schedules, same functionCron("hourly-process","rate(1 hour)",processor)Cron("daily-full-process","rate(1 day)",processor)
Pass a custom JSON payload to the Lambda function:
Cron("batch-job","rate(1 hour)","tasks/batch.handler",payload={"mode":"incremental","batch_size":100})# Full sync on weekendsCron("weekend-sync","cron(0 0 ? * SAT *)","tasks/batch.handler",payload={"mode":"full"})
The payload is passed as the event to your Lambda handler:
defhandler(event,context):mode=event.get("mode","incremental")batch_size=event.get("batch_size",50)# Process based on payload
Linking resources
Connect your scheduled function to other resources using links:
Cron("daily-report","cron(0 6 * * ? *)",# 6 AM UTC daily"tasks/report.handler",memory=1024,timeout=300,payload={"report_type":"daily"})
Customization
The Cron component supports the customize parameter to override underlying Pulumi resource properties. For an overview of how customization works, see the Customization guide.