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 ApiGatewayV2 component lets you add an Amazon API Gateway HTTP API to your app.

Constructor

sst.config.ts
const api = new sst.aws.ApiGatewayV2("MyApi");

Parameters

domain

domain
string | object
Set a custom domain for your HTTP API. Supports AWS Route 53, Cloudflare, and Vercel.
{
  domain: "api.example.com"
}
For Cloudflare domains:
{
  domain: {
    name: "api.example.com",
    dns: sst.cloudflare.dns()
  }
}

cors

cors
boolean | object
default:"true"
Configure CORS (Cross-origin resource sharing) settings for your HTTP API.
{
  cors: {
    allowMethods: ["GET", "POST"],
    allowOrigins: ["https://example.com"]
  }
}
Disable CORS:
{
  cors: false
}
Link resources to all routes. These will be merged with resources linked to individual routes.
{
  link: [bucket, stripeKey]
}

Properties

url

nodes

Methods

route

SDK

Access the API URL in your function code:
src/lambda.ts
import { Resource } from "sst";

console.log(Resource.MyApi.url);

Examples

Add routes

sst.config.ts
const api = new sst.aws.ApiGatewayV2("MyApi");

api.route("GET /", "src/get.handler");
api.route("POST /", "src/post.handler");

Add a custom domain

sst.config.ts
new sst.aws.ApiGatewayV2("MyApi", {
  domain: "api.example.com"
});
sst.config.ts
const bucket = new sst.aws.Bucket("MyBucket");

const api = new sst.aws.ApiGatewayV2("MyApi", {
  link: [bucket]
});

api.route("GET /", "src/get.handler");

Configure CORS

sst.config.ts
new sst.aws.ApiGatewayV2("MyApi", {
  cors: {
    allowMethods: ["GET", "POST", "DELETE"],
    allowOrigins: ["https://example.com"]
  }
});