Skip to main content

Architecture

AWS SAM compiles the template and deploys via CloudFormation, producing an API Gateway REST API backed by a single Lambda function running the Express app.
AWS SAM → CloudFormation → API Gateway REST → Lambda (Node.js 20, 256 MB, 10s timeout)
                                                   └── Express App (src/server.ts)
Lambda handler: dist/lambda.handler API Gateway caching is enabled only in the production environment, with a 600-second TTL on GET endpoints.
The API Gateway stage prefix (/qa, /staging, /production) is stripped from the path before the request reaches Express. The Lambda handler (src/lambda.ts) removes the stage segment from event.path so routes work identically across all environments.

Prerequisites

  • AWS CLI configured with valid credentials
  • AWS SAM CLI installed
  • Node.js >= 18 and npm >= 9

Deploy

1

Install dependencies

npm install
2

Build for Lambda

This compiles TypeScript and copies src/swagger.yaml to dist/ so the Lambda bundle includes the OpenAPI spec:
npm run build:lambda
3

Build the SAM application

sam build
4

Deploy to an environment

Use --config-env to target a specific environment defined in samconfig.toml:
sam deploy --config-env qa
5

Retrieve the API URL

After a successful deploy, SAM prints the stack outputs. The ApiUrl output contains the base URL for the deployed API:
https://{id}.execute-api.{region}.amazonaws.com/{stage}
Append /api/v2026 to reach the API endpoints, or /docs for the Swagger UI.

Environments

The three environments are defined in samconfig.toml with the following parameters:
EnvironmentStack nameCacheCACHE_TTL
QAduitama-taxi-pricing-qaDisabled0
Stagingduitama-taxi-pricing-stagingDisabled0
Productionduitama-taxi-pricing-productionEnabled (600 s on GET)600
All environments deploy to us-east-1.

Cached endpoints (production only)

API Gateway caches responses for the following GET endpoints with a 600-second TTL:
EndpointMethod
/api/v2026/zonesGET
/api/v2026/barriosGET
/api/v2026/rutas-especialesGET
/api/v2026/sectorGET
All other methods and paths have caching disabled (/*CachingEnabled: false).

Lambda configuration

These values are set globally in template.yaml under Globals.Function:
SettingValue
Runtimenodejs20.x
Memory256 MB
Timeout10 seconds
NODE_ENVResolved from NodeEnv parameter (qa, staging, or production)
CACHE_TTLResolved from CacheTtl parameter

Build docs developers (and LLMs) love