DEV Community

Alex Spinov
Alex Spinov

Posted on

SST Has a Free API You Should Know About

SST (Serverless Stack) lets you build full-stack apps on AWS with TypeScript — and its constructs make AWS APIs feel simple.

Define Your API

// sst.config.ts
export default $config({
  app(input) {
    return { name: 'my-app', removal: 'remove' }
  },
  async run() {
    const api = new sst.aws.ApiGatewayV2('MyApi')

    api.route('GET /users', 'src/users.list')
    api.route('POST /users', 'src/users.create')
    api.route('GET /users/{id}', 'src/users.get')
    api.route('DELETE /users/{id}', 'src/users.remove')

    return { url: api.url }
  }
})
Enter fullscreen mode Exit fullscreen mode

Lambda Handlers

// src/users.ts
export const list = async () => {
  const users = await db.select().from(usersTable)
  return { statusCode: 200, body: JSON.stringify(users) }
}

export const create = async (event) => {
  const body = JSON.parse(event.body)
  const [user] = await db.insert(usersTable).values(body).returning()
  return { statusCode: 201, body: JSON.stringify(user) }
}
Enter fullscreen mode Exit fullscreen mode

Database (RDS)

const database = new sst.aws.Postgres('MyDatabase', {
  scaling: { min: '0.5 ACU', max: '4 ACU' }
})

// Link to functions
api.route('GET /users', {
  handler: 'src/users.list',
  link: [database]
})

// In handler — use Resource to get connection
import { Resource } from 'sst'
const db = drizzle(Resource.MyDatabase)
Enter fullscreen mode Exit fullscreen mode

Cron Jobs

new sst.aws.Cron('DailyCleanup', {
  schedule: 'rate(1 day)',
  job: 'src/cron/cleanup.handler'
})
Enter fullscreen mode Exit fullscreen mode

Auth

const auth = new sst.aws.Auth('MyAuth', {
  authenticator: 'src/auth.handler'
})

// In auth handler
export const handler = AuthHandler({
  providers: {
    google: GoogleAdapter({ clientID: Resource.GoogleClientId.value })
  },
  callbacks: {
    auth: { async allowClient() { return true } },
    connect: { async afterConnect(ctx) { /* create user */ } }
  }
})
Enter fullscreen mode Exit fullscreen mode

Live Lambda Development

SST's sst dev connects your local machine to AWS:

sst dev
# Changes to Lambda code take effect in <1 second
# No deploy needed — live debugging in your IDE
Enter fullscreen mode Exit fullscreen mode

Real-World Use Case

A startup was hand-writing CloudFormation for their serverless app: API Gateway + Lambda + RDS + S3 + Cognito. 2,000 lines of YAML, deploying took 15 minutes, debugging was impossible. They rewrote with SST: 200 lines of TypeScript, sst dev for instant feedback, type-safe resource linking. Same AWS infrastructure, 10x better developer experience.

SST made AWS serverless actually enjoyable.


Build Smarter Data Pipelines

Need to scrape websites, extract APIs, or automate data collection? Check out my ready-to-use scrapers on Apify — no coding required.

Custom scraping solution? Email me at spinov001@gmail.com — fast turnaround, fair prices.

Top comments (0)