{"record":{"id":"35336c1ed3b7ffc7","repo":"anomalyco/sst","slug":"you-cannot-provide-both-a-function-and-a-task-in-t","errorCode":null,"errorMessage":"You cannot provide both a function and a task in the \"${name}\" CronV2 component.","messagePattern":"You cannot provide both a function and a task in the \"(.+?)\" CronV2 component\\.","errorType":"exception","errorClass":"VisibleError","httpStatus":null,"severity":"error","filePath":"platform/src/components/aws/cron-v2.ts","lineNumber":336,"sourceCode":"\n    this._name = name;\n    this.fn = fn;\n    this._role = role;\n    this._schedule = schedule;\n\n    function normalizeFunction() {\n      if (args.job && args.function)\n        throw new VisibleError(\n          `You cannot provide both \"job\" and \"function\" in the \"${name}\" CronV2 component. The \"job\" property has been deprecated. Use \"function\" instead.`,\n        );\n\n      const input = args.function ?? args.job;\n      return input ? output(input) : undefined;\n    }\n\n    function normalizeTargets() {\n      if (fnArgs && args.task)\n        throw new VisibleError(\n          `You cannot provide both a function and a task in the \"${name}\" CronV2 component.`,\n        );\n      if (!fnArgs && !args.task)\n        throw new VisibleError(\n          `You must provide either a function or a task in the \"${name}\" CronV2 component.`,\n        );\n    }\n\n    function createFunction() {\n      if (!fnArgs) return;\n\n      return fnArgs.apply((fnArgs) =>\n        functionBuilder(`${name}Handler`, fnArgs, {}, undefined, {\n          parent,\n        }),\n      );\n    }\n","sourceCodeStart":318,"sourceCodeEnd":354,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/platform/src/components/aws/cron-v2.ts#L318-L354","documentation":"CronV2 requires exactly one schedule target: either a Lambda `function` or an ECS `task`. This error is thrown in normalizeTargets when both a function/job and a `task` are provided, since EventBridge Scheduler can only have one unambiguous target per schedule.","triggerScenarios":"`new sst.aws.CronV2(name, { schedule, task, function })` or `new sst.aws.CronV2(name, { schedule, task, job })` — both `fnArgs` and `args.task` truthy.","commonSituations":"Refactoring a cron that used to run a function into one that runs an ECS task without deleting the `function` key; combining two cron examples; a shared config merging function- and task-based crons.","solutions":["Delete the `function` (or `job`) property if the cron should run the ECS task","Delete the `task` property if the cron should invoke the Lambda function","Split into two separate CronV2 components if you genuinely need both targets"],"exampleFix":"// before\nnew sst.aws.CronV2(\"MyCron\", {\n  schedule: \"rate(1 day)\",\n  task: myTask,\n  function: handler,\n});\n// after\nnew sst.aws.CronV2(\"MyCron\", {\n  schedule: \"rate(1 day)\",\n  task: myTask,\n});","handlingStrategy":"validation","validationCode":"function validateCronV2Target(args: sst.aws.CronV2Args) {\n  const hasFn = !!(args.function || args.job);\n  if (hasFn && args.task) throw new Error(\"Provide either a function or a task, not both\");\n}","typeGuard":"function hasSingleTarget(args: { function?: unknown; job?: unknown; task?: unknown }): boolean {\n  const fn = Boolean(args.function ?? args.job);\n  const task = Boolean(args.task);\n  return fn !== task;\n}","tryCatchPattern":"try {\n  new sst.aws.CronV2(\"MyCron\", args);\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"both a function and a task\")) {\n    console.error(\"Delete either the function or the task property\");\n  } else throw e;\n}","preventionTips":["Decide the target type (Lambda vs ECS) before writing the cron config","Never copy both function- and task-based cron examples into one component","Conditionally spread target props: only one of `function`/`task`"],"tags":["config","validation","cron","ecs"],"backgroundTag":"conflicting-component-props","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}