anomalyco/sst · error · Error

Invalid function definition for the "${name}" Function

Error message

Invalid function definition for the "${name}" Function

What it means

functionBuilder accepts either a function config object or a qualified ARN; if the definition matches neither shape it throws "Invalid function definition for the <name> Function". This is a programmer/config error, not a VisibleError, indicating the definition type is unsupported.

Source

Thrown at platform/src/components/aws/helpers/function-builder.ts:131

              definition.environment,
            ]).apply(([defaultEnvironment, environment]) => ({
              ...(defaultEnvironment ?? {}),
              ...(environment ?? {}),
            })),
            permissions: all([
              defaultArgs?.permissions,
              definition.permissions,
            ]).apply(([defaultPermissions, permissions]) => [
              ...(defaultPermissions ?? []),
              ...(permissions ?? []),
            ]),
          },
          opts || {},
        ),
      );
      return buildResult(fn);
    }
    throw new Error(`Invalid function definition for the "${name}" Function`);
  });
}

View on GitHub (pinned to a0bd20f762)

Solutions

  1. Log/inspect the definition value to confirm its type before building
  2. Provide a valid handler-based config object (handler, runtime, etc.)
  3. Ensure a valid qualified ARN string when referencing an existing function

Example fix

// before
const def: any = process.env.FN // undefined at build time
new sst.aws.Function("Api", def)
// after
new sst.aws.Function("Api", { handler: "src/api.handler" })
Defensive patterns

Strategy: validation

Validate before calling

function assertFunctionDef(name: string, def: unknown) {
  const isArn = typeof def === "string" && def.startsWith("arn:");
  const isConfig = typeof def === "object" && def !== null && "handler" in (def as any);
  if (!isArn && !isConfig) throw new Error(`Invalid function definition for "${name}"`);
}

Type guard

const isValidFunctionDef = (def: unknown): def is string | { handler: string } =>
  (typeof def === "string" && def.startsWith("arn:")) ||
  (typeof def === "object" && def !== null && "handler" in def);

Try / catch

try { const f = functionBuilder(name, def); } catch (e) { /* report invalid definition shape */ }

Prevention

When it happens

Trigger: Passing a definition that is neither a valid FunctionArgs object nor an ARN string — e.g. undefined, null, an empty object with no handler, or wrong type (number/boolean) to any component that calls functionBuilder.

Common situations: Conditional expressions yielding undefined; refactoring that removed the handler field; passing a Pulumi resource object where a raw string or args object was expected.

Related errors


AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30). Data as JSON: /api/errors/faab44177fbd1c74. Report an issue: GitHub.