{"record":{"id":"67c479164351e1dc","repo":"anomalyco/sst","slug":"you-cannot-provide-both-a-function-and-a-task-in-t-67c479","errorCode":null,"errorMessage":"You cannot provide both a function and a task in the \"${name}\" Cron component.","messagePattern":"You cannot provide both a function and a task in the \"(.+?)\" Cron component\\.","errorType":"exception","errorClass":"VisibleError","httpStatus":null,"severity":"error","filePath":"platform/src/components/aws/cron.ts","lineNumber":271,"sourceCode":"\n    this.name = name;\n    this.fn = fn;\n    this.rule = rule;\n    this.target = target;\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}\" Cron 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}\" Cron component.`,\n        );\n    }\n\n    function createRule() {\n      return new cloudwatch.EventRule(\n        ...transform(\n          args.transform?.rule,\n          `${name}Rule`,\n          {\n            scheduleExpression: args.schedule,\n            state: enabled.apply((v) => (v ? \"ENABLED\" : \"DISABLED\")),\n          },\n          { parent },\n        ),\n      );\n    }\n","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/platform/src/components/aws/cron.ts#L253-L289","documentation":"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.","triggerScenarios":"`new sst.aws.Cron(name, { schedule, task, function })` or with the deprecated `job` alongside `task`.","commonSituations":"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.","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"],"exampleFix":"// before\nnew sst.aws.Cron(\"MyCron\", {\n  schedule: \"rate(1 day)\",\n  function: handler,\n  task: myTask,\n});\n// after\nnew sst.aws.Cron(\"MyCron\", {\n  schedule: \"rate(1 day)\",\n  function: handler,\n});","handlingStrategy":"validation","validationCode":"function validateCronTarget(args: sst.aws.CronArgs) {\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  return Boolean(args.function ?? args.job ?? args.task) && !(args.task && (args.function || args.job));\n}","tryCatchPattern":"try {\n  new sst.aws.Cron(\"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":["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"],"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"}