Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/anomalyco/sst/llms.txt

Use this file to discover all available pages before exploring further.

The Function component lets you add serverless functions to your app. It uses AWS Lambda.

Constructor

sst.config.ts
new sst.aws.Function("MyFunction", {
  handler: "src/lambda.handler"
});

Parameters

handler

handler
string
required
Path to the handler for the function.
  • For Node.js: {path}/{file}.{method} format
  • For Python: {path}/{file}.{method} format
  • For Go: {path} to the Go module
  • For Rust: {path} to the Rust crate
{
  handler: "packages/functions/src/main.handler"
}

runtime

runtime
string
default:"nodejs24.x"
The language runtime for the function.
{
  runtime: "nodejs24.x"
}
Supported values: "nodejs18.x", "nodejs20.x", "nodejs22.x", "nodejs24.x", "go", "rust", "provided.al2", "provided.al2023", "python3.9", "python3.10", "python3.11", "python3.12", "python3.13"

timeout

timeout
duration
default:"20 seconds"
The maximum amount of time the function can run. Between 1 second and 900 seconds (15 minutes).
{
  timeout: "900 seconds"
}
If a function is connected to API Gateway, it will time out after 30 seconds regardless of this setting.

memory

memory
string
default:"1024 MB"
The amount of memory allocated for the function. Between 128 MB and 10240 MB in 1 MB increments.
{
  memory: "2048 MB"
}
While less memory is cheaper, larger functions can process faster and might be more cost effective.
Link resources to your function. This will:
  1. Grant permissions to access the resources
  2. Allow you to access them in your function using the SDK
{
  link: [bucket, stripeKey]
}

environment

environment
Record<string, string>
Key-value pairs of Lambda environment variables.
{
  environment: {
    DEBUG: "true"
  }
}
The total size of environment variables cannot exceed 4 KB.

permissions

permissions
array
Permissions to access other resources. These are added to the function’s IAM role.
{
  permissions: [
    {
      actions: ["s3:GetObject", "s3:PutObject"],
      resources: ["arn:aws:s3:::my-bucket/*"]
    }
  ]
}
If you link the function to a resource, the permissions to access it are automatically added.

url

url
boolean | object
default:"false"
Enable Lambda function URLs.
{
  url: true
}
Configure the authorization and CORS settings:
{
  url: {
    authorization: "iam",
    cors: {
      allowOrigins: ["https://example.com"]
    }
  }
}

vpc

vpc
Vpc | object
Connect the function to private subnets in a VPC.
{
  vpc: myVpc
}
Where myVpc is:
const myVpc = new sst.aws.Vpc("MyVpc");

Properties

name

arn

url

nodes

SDK

When you link a Function to another resource, you can access it in your function code using the SDK.
src/lambda.ts
import { Resource } from "sst";

console.log(Resource.MyFunction.name);

Examples

Set additional config

sst.config.ts
new sst.aws.Function("MyFunction", {
  handler: "src/lambda.handler",
  timeout: "3 minutes",
  memory: "2048 MB"
});
Link resources to the function:
sst.config.ts
const bucket = new sst.aws.Bucket("MyBucket");

new sst.aws.Function("MyFunction", {
  handler: "src/lambda.handler",
  link: [bucket]
});
Access linked resources in your function:
src/lambda.ts
import { Resource } from "sst";

console.log(Resource.MyBucket.name);

Enable function URLs

sst.config.ts
new sst.aws.Function("MyFunction", {
  handler: "src/lambda.handler",
  url: true
});

Customize bundling

sst.config.ts
new sst.aws.Function("MyFunction", {
  handler: "src/lambda.handler",
  nodejs: {
    install: ["pg"]
  }
});