anomalyco/sst · error · VisibleError
You cannot provide both a function and a task in the "${name
Error message
You cannot provide both a function and a task in the "${name}" Cron component. What it means
The Cron component supports either a Lambda function or an ECS task as the schedule target. This VisibleError is thrown in normalizeTargets when both `function`/`job` and `task` are supplied, which would leave the EventBridge rule target ambiguous.
Source
Thrown at platform/src/components/aws/cron.ts:271
this.name = name;
this.fn = fn;
this.rule = rule;
this.target = target;
function normalizeFunction() {
if (args.job && args.function)
throw new VisibleError(
`You cannot provide both "job" and "function" in the "${name}" Cron component. The "job" property has been deprecated. Use "function" instead.`,
);
const input = args.function ?? args.job;
return input ? output(input) : undefined;
}
function normalizeTargets() {
if (fnArgs && args.task)
throw new VisibleError(
`You cannot provide both a function and a task in the "${name}" Cron component.`,
);
}
function createRule() {
return new cloudwatch.EventRule(
...transform(
args.transform?.rule,
`${name}Rule`,
{
scheduleExpression: args.schedule,
state: enabled.apply((v) => (v ? "ENABLED" : "DISABLED")),
},
{ parent },
),
);
}
View on GitHub (pinned to a0bd20f762)
Solutions
- Delete the `function` (or `job`) property to run the ECS task
- Delete the `task` property to invoke the Lambda function
- Create two separate Cron components if both targets are genuinely needed
Example fix
// before
new sst.aws.Cron("MyCron", {
schedule: "rate(1 day)",
function: handler,
task: myTask,
});
// after
new sst.aws.Cron("MyCron", {
schedule: "rate(1 day)",
function: handler,
}); Defensive patterns
Strategy: validation
Validate before calling
function validateCronTarget(args: sst.aws.CronArgs) {
const hasFn = !!(args.function || args.job);
if (hasFn && args.task) throw new Error("Provide either a function or a task, not both");
} Type guard
function hasSingleTarget(args: { function?: unknown; job?: unknown; task?: unknown }): boolean {
return Boolean(args.function ?? args.job ?? args.task) && !(args.task && (args.function || args.job));
} Try / catch
try {
new sst.aws.Cron("MyCron", args);
} catch (e) {
if (e instanceof Error && e.message.includes("both a function and a task")) {
console.error("Delete either the function or the task property");
} else throw e;
} Prevention
- Choose one target type per cron component
- Spread target props conditionally so only one is ever set
- Review merged config files for duplicated target keys
When it happens
Trigger: `new sst.aws.Cron(name, { schedule, task, function })` or with the deprecated `job` alongside `task`.
Common situations: Migrating a function-based cron to a task-based one without removing the function; merging two cron definitions; shared config that conditionally sets both keys.
Related errors
- You cannot provide both a function and a task in the "${name
- You cannot provide both "job" and "function" in the "${name}
- You must provide either a function or a task in the "${name}
- You cannot provide both "job" and "function" in the "${name}
- Unsupported CPU: ${v}. The supported values for CPU are ${Ob
AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30).
Data as JSON: /api/errors/67c479164351e1dc.
Report an issue: GitHub.