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
- Log/inspect the definition value to confirm its type before building
- Provide a valid handler-based config object (handler, runtime, etc.)
- 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
- Type definitions as FunctionArgs | string, not any
- Check env-driven definitions resolve before build
- Keep handler field mandatory in configs
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
- Invalid function definition for the "${name}" Function
- The provided ARN "${arn}" is not a Lambda function ARN.
- The `namespaceId` property must be a positive integer.
- Invalid size ${size}
- Record name "${recordName}" is not a subdomain of "${domain}
AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30).
Data as JSON: /api/errors/faab44177fbd1c74.
Report an issue: GitHub.