Serverless REST API

beginner

API Gateway + Lambda + DynamoDB with TypeScript. Full CRUD boilerplate with IAM roles, environment config, and local testing setup.

Quick Start

Via CLI (recommended)

npx cdk-starter create

Then select "Serverless REST API" from the prompt

Or scaffold directly

npx cdk-starter create --starter serverless-api

README

Serverless REST API

A production-ready REST API built with API Gateway + Lambda + DynamoDB and CDK v2 (TypeScript).

What's included

  • API Gateway REST API with structured access logs, X-Ray tracing, and CORS
  • 5 Lambda handlers (list, get, create, update, delete) bundled with esbuild
  • DynamoDB table with PAY_PER_REQUEST billing, encryption, and point-in-time recovery
  • IAM least-privilege grants per handler
  • CloudWatch log groups with 1-week retention

Prerequisites

  • Node.js ≥ 20
  • AWS CLI configured (aws configure)
  • AWS CDK bootstrapped in your account/region (npx cdk bootstrap)

Getting started

npm install

# Preview changes
npx cdk diff

# Deploy to AWS
npx cdk deploy

The deploy output will print your API URL:

Outputs:
ServerlessApiStack.ApiUrl = https://xxxx.execute-api.us-east-1.amazonaws.com/v1/

API endpoints

Method Path Description
GET /items List all items
POST /items Create an item
GET /items/{id} Get one item
PUT /items/{id} Update an item
DELETE /items/{id} Delete an item

Environment

No .env file needed — all config is passed via CDK environment variables at deploy time.

To target a specific account and region:

CDK_DEFAULT_ACCOUNT=123456789012 CDK_DEFAULT_REGION=us-west-2 npx cdk deploy

Tear down

npx cdk destroy

Note: the DynamoDB table has removalPolicy: RETAIN — delete it manually in the AWS console if needed.