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 Nextjs component lets you deploy Next.js apps on AWS. It uses OpenNext to build your Next.js app for AWS.

Constructor

sst.config.ts
new sst.aws.Nextjs("MyWeb");

Parameters

path

path
string
default:"."
Path to the Next.js app directory relative to sst.config.ts.
{
  path: "packages/web"
}

domain

domain
string | object
Set a custom domain for your Next.js app. Supports AWS Route 53, Cloudflare, and Vercel.
{
  domain: "example.com"
}
Redirect www to apex domain:
{
  domain: {
    name: "example.com",
    redirects: ["www.example.com"]
  }
}
Link resources to your Next.js app. This grants permissions and allows you to access them via the SDK.
{
  link: [bucket, stripeKey]
}

environment

environment
Record<string, string>
Set environment variables for your Next.js app.
{
  environment: {
    API_URL: api.url,
    NEXT_PUBLIC_STRIPE_KEY: "pk_test_123"
  }
}
Prefix with NEXT_PUBLIC_ to access variables in the browser.

openNextVersion

openNextVersion
string
Configure the OpenNext version for building your app. By default, SST auto-detects based on your Next.js version.
{
  openNextVersion: "3.4.1"
}

imageOptimization

imageOptimization
object
default:"{memory: '1536 MB'}"
Configure the Lambda function for image optimization.
{
  imageOptimization: {
    memory: "2048 MB"
  }
}

Properties

url

nodes

SDK

Access linked resources in your Next.js app:
app/page.tsx
import { Resource } from "sst";

console.log(Resource.MyBucket.name);

Examples

Change the path

sst.config.ts
new sst.aws.Nextjs("MyWeb", {
  path: "packages/web"
});

Add a custom domain

sst.config.ts
new sst.aws.Nextjs("MyWeb", {
  domain: "my-app.com"
});
sst.config.ts
const bucket = new sst.aws.Bucket("MyBucket");

new sst.aws.Nextjs("MyWeb", {
  link: [bucket]
});
Access them in your app:
app/page.tsx
import { Resource } from "sst";
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";

const client = new S3Client();
await client.send(new PutObjectCommand({
  Bucket: Resource.MyBucket.name,
  Key: "file.txt",
  Body: "Hello"
}));

Redirect www to apex

sst.config.ts
new sst.aws.Nextjs("MyWeb", {
  domain: {
    name: "my-app.com",
    redirects: ["www.my-app.com"]
  }
});