anomalyco/sst · error · Error
Invalid function definition for the "${name}" Function
Error message
Invalid function definition for the "${name}" Function What it means
SST's Function component accepts either a function definition object or a string ARN. When a definition entry is neither of these (an entry in a Function list with no matching constructor branch), the component cannot build a Lambda and throws this Error to stop deployment early.
Source
Thrown at platform/src/components/aws/function.ts:3112
...transform(
argsTransform,
name,
{
...definition,
...override,
permissions: all([
definition.permissions,
override?.permissions,
]).apply(([permissions, overridePermissions]) => [
...(permissions ?? []),
...(overridePermissions ?? []),
]),
},
opts || {},
),
);
}
throw new Error(`Invalid function definition for the "${name}" Function`);
});
}
/** @internal */
public getSSTLink() {
return {
properties: {
name: this.name,
url: this.urlEndpoint,
...(this.durable
? {
qualifier: this.qualifier,
}
: {}),
},
include: [
permission({
actions: [View on GitHub (pinned to a0bd20f762)
Solutions
- Check the value passed for the function: it must be a valid FunctionArgs object with a resolvable handler, or a string ARN of an existing Lambda
- Verify the handler file exists at src/<handler>.ts relative to the app and the export name matches
- If referencing another Function, pass the Function component instance or its .arn, not an arbitrary string
- Log the value just before creating the Function to confirm it is not undefined due to a failed conditional
Example fix
// before
new Function(stack, "Fn", undefined as any);
// after
new Function(stack, "Fn", { handler: "src/api.handler" }); Defensive patterns
Strategy: validation
Validate before calling
const def = typeof fn === "string" ? { arn: fn } : fn;
if (!def || typeof def !== "object" || (!def.handler && !def.arn)) {
throw new Error(`Function definition invalid: ${JSON.stringify(def)}`);
} Type guard
function isFunctionDef(v: unknown): v is { handler: string } {
return typeof v === "object" && v !== null && "handler" in v && typeof (v as any).handler === "string";
} Try / catch
try {
new sst.aws.Function(stack, name, args);
} catch (e) {
console.error(`Function "${name}" rejected definition:`, args);
throw e;
} Prevention
- Always pass FunctionArgs objects or Function instances, never undefined/null
- Verify handler paths resolve to existing exported functions before deploy
- Run sst diff to catch definition issues before deploying
- Keep conditional function creation explicit instead of relying on undefined fallbacks
When it happens
Trigger: Passing a string that is not recognized as an ARN/reference, or an object that fails the FunctionArgs shape (e.g. missing handler when no bundle provided), or a null/undefined entry in a functions array.
Common situations: Typo in the handler path, using a plain object where a Function or its args were expected, migrating from SST v2 config shape to v3, passing the result of a conditional expression that resolves to undefined.
Related errors
- The provided ARN "${arn}" is not a Lambda function ARN.
- Invalid function definition for the "${name}" Function
- Cannot access `nodes.loadBalancer` when no public ports are
- You must provide the ports to expose via "loadBalancer.rules
- You must provide a container name in "loadBalancer.rules" wh
AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30).
Data as JSON: /api/errors/25663479d2b9f4b2.
Report an issue: GitHub.