CronV2
The CronV2 component lets you add cron jobs to your app
using Amazon EventBridge Scheduler. The cron job can invoke a Function or a container Task.
Cron job function
Pass in a schedule and a function that’ll be executed.
new sst.aws.CronV2("MyCronJob", { function: "src/cron.handler", schedule: "rate(1 minute)"});Cron job container task
Create a container task and pass in a schedule and a task that’ll be executed.
const cluster = new sst.aws.Cluster("MyCluster");const task = new sst.aws.Task("MyTask", { cluster });
new sst.aws.CronV2("MyCronJob", { task, schedule: "rate(1 day)"});Set a timezone
new sst.aws.CronV2("MyCronJob", { function: "src/cron.handler", schedule: "cron(15 10 * * ? *)", timezone: "America/New_York"});Configure retries
new sst.aws.CronV2("MyCronJob", { function: "src/cron.handler", schedule: "rate(1 minute)", retries: 3});One-time schedule
new sst.aws.CronV2("MyCronJob", { function: "src/cron.handler", schedule: "at(2025-06-01T10:00:00)"});Customize the function
new sst.aws.CronV2("MyCronJob", { schedule: "rate(1 minute)", function: { handler: "src/cron.handler", timeout: "60 seconds" }});Constructor
new CronV2(name, args, opts?)Parameters
-
namestring -
argsCronV2Args -
opts?ComponentResourceOptions
CronV2Args
dlq?
Type Input<string>
The ARN of an SQS queue to use as a dead-letter queue. When all retry attempts are exhausted, failed events are sent to this queue.
{ dlq: myQueue.arn}enabled?
Type Input<boolean>
Default true
Configures whether the cron job is enabled. When disabled, the cron job won’t run.
{ enabled: false}event?
Type Input<Record<string, Input<string>>>
The event that’ll be passed to the function or task.
{ event: { foo: "bar", }}For Lambda functions, the event will be passed to the function as an event.
function handler(event) { console.log(event.foo);}For ECS Fargate tasks, the event will be passed to the task as the SST_EVENT
environment variable.
const event = JSON.parse(process.env.SST_EVENT);console.log(event.foo);function?
Type Input<string | FunctionArgs | “arn:aws:lambda:${string}”>
The function that’ll be executed when the cron job runs.
{ function: "src/cron.handler"}You can pass in the full function props.
{ function: { handler: "src/cron.handler", timeout: "60 seconds" }}You can also pass in a function ARN.
{ function: "arn:aws:lambda:us-east-1:000000000000:function:my-sst-app-jayair-MyFunction",}retries?
Type Input<number>
Default 0
The number of retry attempts for failed invocations. Between 0 and 185.
{ retries: 3}schedule
Type Input<“rate(${string})” | “cron(${string})” | “at(${string})”>
The schedule for the cron job.
You can use a rate expression.
{ schedule: "rate(5 minutes)" // schedule: "rate(1 minute)" // schedule: "rate(5 minutes)" // schedule: "rate(1 hour)" // schedule: "rate(5 hours)" // schedule: "rate(1 day)" // schedule: "rate(5 days)"}Or a cron expression.
{ schedule: "cron(15 10 * * ? *)", // 10:15 AM (UTC) every day}Or an at expression for a one-time schedule.
{ schedule: "at(2025-06-01T10:00:00)",}task?
Type Task
The task that’ll be executed when the cron job runs.
For example, let’s say you have a task.
const cluster = new sst.aws.Cluster("MyCluster");const task = new sst.aws.Task("MyTask", { cluster });You can then pass in the task to the cron job.
new sst.aws.CronV2("MyCronJob", { task, schedule: "rate(1 minute)"});timezone?
Type Input<string>
Default “UTC”
The IANA timezone for the cron schedule. When set, the cron expression is evaluated in this timezone, with automatic DST handling.
{ timezone: "America/New_York"}transform?
transform.role?
Type RoleArgs | (args: RoleArgs, opts: ComponentResourceOptions, name: string) => void
Transform the IAM Role resource.
transform.schedule?
Type ScheduleArgs | (args: ScheduleArgs, opts: ComponentResourceOptions, name: string) => void
Transform the EventBridge Scheduler Schedule resource.
Properties
nodes
nodes.role
Type Role
The IAM Role resource.
nodes.schedule
Type Schedule
The EventBridge Scheduler Schedule resource.
nodes.function
Type Output<Function>
The AWS Lambda Function that’ll be invoked when the cron job runs.
nodes.job
Type Output<Function>
The AWS Lambda Function that’ll be invoked when the cron job runs.