Skip to content

feat(deno): Add Deno + Aurora DSQL samples with booking API#950

Open
pyraenix wants to merge 1 commit intoaws-samples:mainfrom
pyraenix:feat/add-deno-samples
Open

feat(deno): Add Deno + Aurora DSQL samples with booking API#950
pyraenix wants to merge 1 commit intoaws-samples:mainfrom
pyraenix:feat/add-deno-samples

Conversation

@pyraenix
Copy link
Copy Markdown

Add Deno runtime samples for connecting to Amazon Aurora DSQL, including a basic client/ORM sample and a real-world booking API sample application. Deno is the first new runtime added to this repository that uses a native (non-Node.js) PostgreSQL driver.

deno/deno-postgres — Basic Client/ORM Sample

Simple connect-and-query example using the native deno-postgres driver (jsr:@db/postgres) with IAM token authentication over SSL verify-full. Demonstrates concurrent queries across multiple connections. Follows the same pattern as javascript/node-postgres.

  • src/example_preferred.ts — main example
  • test/example_preferred.test.ts — integration test
  • deno.json, deno.lock, README.md, .gitignore

deno/booking-api/deno-postgres — Booking API Sample Application

A booking/reservation REST API built with Deno.serve() and deno-postgres, backed by Aurora DSQL. Goes beyond connect-and-query to demonstrate real application patterns:

  • Full CRUD: POST/GET/PUT/DELETE /bookings + GET /health
  • IAM token authentication via @aws-sdk/dsql-signer
  • OCC retry handling for SQLSTATE OC000 concurrency conflicts with exponential backoff + jitter
  • Overlap detection for double-booking prevention within transactions (DSQL has no exclusion constraints)
  • Deno least-privilege permissions model (--allow-net, --allow-env, --allow-read scoped to minimum required)
  • Serverless-ready architecture (deno serve compatible, per-request connections, no mutable global state)
  • UUID primary keys via gen_random_uuid() (DSQL has no sequences)
  • Graceful shutdown with schema teardown on SIGINT/SIGTERM

Testing (all verified against real Aurora DSQL cluster)

  • 20 property-based tests (fast-check): router dispatch, overlap detection symmetry, JSON response format, malformed JSON rejection, OCC error detection/retry/exhaustion/pass-through, token generator error formatting
  • 9 integration tests: full CRUD flow against real DSQL
  • 15 smoke tests (test-api.sh): health check, CRUD, overlap conflict, concurrent OCC conflict, validation errors, cleanup

Documentation

  • Architecture diagram (ASCII art)
  • Create booking request flow diagram
  • Data model diagram
  • Key design decisions table for Aurora DSQL
  • API endpoints table with status codes
  • Error response examples
  • Deno permissions model explanation
  • OCC retry behavior section
  • Deno Deploy deployment instructions
  • Example curl commands for all endpoints
  • Project structure overview

Root README

Updated the repository root README.md to include Deno in the Client/ORM table and the booking API in the Sample Applications table.

Technical Notes

  • npm:pg (node-postgres) was evaluated but does not work with Aurora DSQL from Deno due to a TLS compatibility issue in Deno's Node.js compat layer. Only the native deno-postgres driver is included.
  • Authentication and cluster management samples are intentionally omitted — they are pure AWS SDK calls with no Deno-specific value, matching the pattern of TypeScript and PHP samples.

By submitting this pull request, I confirm that my contribution is made under
the terms of the MIT-0 license.

Thank you for your contribution!

Add Deno runtime samples for connecting to Amazon Aurora DSQL,
including a basic client/ORM sample and a real-world booking API
sample application. Deno is the first new runtime added to this
repository that uses a native (non-Node.js) PostgreSQL driver.

## deno/deno-postgres — Basic Client/ORM Sample

Simple connect-and-query example using the native deno-postgres
driver (jsr:@db/postgres) with IAM token authentication over
SSL verify-full. Demonstrates concurrent queries across multiple
connections. Follows the same pattern as javascript/node-postgres.

- src/example_preferred.ts — main example
- test/example_preferred.test.ts — integration test
- deno.json, deno.lock, README.md, .gitignore

## deno/booking-api/deno-postgres — Booking API Sample Application

A booking/reservation REST API built with Deno.serve() and
deno-postgres, backed by Aurora DSQL. Goes beyond connect-and-query
to demonstrate real application patterns:

- Full CRUD: POST/GET/PUT/DELETE /bookings + GET /health
- IAM token authentication via @aws-sdk/dsql-signer
- OCC retry handling for SQLSTATE OC000 concurrency conflicts
  with exponential backoff + jitter
- Overlap detection for double-booking prevention within
  transactions (DSQL has no exclusion constraints)
- Deno least-privilege permissions model (--allow-net, --allow-env,
  --allow-read scoped to minimum required)
- Serverless-ready architecture (deno serve compatible, per-request
  connections, no mutable global state)
- UUID primary keys via gen_random_uuid() (DSQL has no sequences)
- Graceful shutdown with schema teardown on SIGINT/SIGTERM

### Testing (all verified against real Aurora DSQL cluster)

- 20 property-based tests (fast-check): router dispatch, overlap
  detection symmetry, JSON response format, malformed JSON
  rejection, OCC error detection/retry/exhaustion/pass-through,
  token generator error formatting
- 9 integration tests: full CRUD flow against real DSQL
- 15 smoke tests (test-api.sh): health check, CRUD, overlap
  conflict, concurrent OCC conflict, validation errors, cleanup

### Documentation

- Architecture diagram (ASCII art)
- Create booking request flow diagram
- Data model diagram
- Key design decisions table for Aurora DSQL
- API endpoints table with status codes
- Error response examples
- Deno permissions model explanation
- OCC retry behavior section
- Deno Deploy deployment instructions
- Example curl commands for all endpoints
- Project structure overview

## Root README

Updated the repository root README.md to include Deno in the
Client/ORM table and the booking API in the Sample Applications
table.

## Technical Notes

- npm:pg (node-postgres) was evaluated but does not work with
  Aurora DSQL from Deno due to a TLS compatibility issue in
  Deno's Node.js compat layer. Only the native deno-postgres
  driver is included.
- Authentication and cluster management samples are intentionally
  omitted — they are pure AWS SDK calls with no Deno-specific
  value, matching the pattern of TypeScript and PHP samples.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants