Cognito Auth + API Gateway
intermediateCognito User Pool with hosted UI, SPA and server-side app clients, and an API Gateway REST API protected by a Cognito JWT authorizer. Includes public and protected Lambda endpoints.
Quick Start
Via CLI (recommended)
npx cdk-starter create Then select "Cognito Auth + API Gateway" from the prompt
Or scaffold directly
npx cdk-starter create --starter cognito-auth README
Cognito Auth + API Gateway
Cognito User Pool with hosted UI, SPA and server-side app clients, and an API Gateway REST API with Cognito JWT authoriser.
Endpoints
| Method | Path | Auth | Handler |
|---|---|---|---|
| GET | /health | None | Mock 200 |
| GET | /me | Cognito JWT | src/profile.ts |
| GET | /admin/users | Cognito JWT | src/admin.ts |
Hosted UI
After deploy, use the CognitoLoginUrl output to access the Cognito sign-up/sign-in UI.
Callback URLs
Update the callback and logout URLs in lib/cognito-auth-stack.ts for production.
Prerequisites
- Node.js ≥ 20
- AWS CLI configured (
aws configure) - CDK bootstrapped (
npx cdk bootstrap)
Deploy
npm install
npx cdk diff
npx cdk deploy
Tear down
npx cdk destroy