Cron
Reference doc for the `sst.aws.Cron` component.
The Cron
component lets you add cron jobs to your app.
It uses Amazon Event Bus.
Minimal example
Pass in a schedule
and a job
function that’ll be executed.
new sst.aws.Cron("MyCronJob", { job: "src/cron.handler", schedule: "rate(1 minute)"});
Customize the function
new sst.aws.Cron("MyCronJob", { schedule: "rate(1 minute)", job: { handler: "src/cron.handler", timeout: "60 seconds" }});
Constructor
new Cron(name, args, opts?)
Parameters
-
name
string
-
args
CronArgs
-
opts?
ComponentResourceOptions
CronArgs
job
Type Input
<
string
|
FunctionArgs
>
The function that’ll be executed when the cron job runs.
{ job: "src/cron.handler"}
Alternatively, you can pass in the full function props.
{ job: { handler: "src/cron.handler", timeout: "60 seconds" }}
schedule
Type Input
<
“
rate(${string})
”
|
“
cron(${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}
transform?
transform.rule?
Type EventRuleArgs
|
(
args
:
EventRuleArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the EventBridge Rule resource.
transform.target?
Type EventTargetArgs
|
(
args
:
EventTargetArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the EventBridge Target resource.
Properties
nodes
nodes.job
Type Output
<
Function
>
The AWS Lambda Function that’s invoked when the cron job runs.
nodes.rule
Type EventRule
The EventBridge Rule resource.
nodes.target
Type EventTarget
The EventBridge Target resource.