Local setup
1. Clone and install
git clone git@github.com:caradvice/drive-apig.git
cd drive-apig
export GH_REGISTRY_TOKEN="ghp_..." # read:packages scope
export SERVERLESS_ACCESS_KEY="..." # from serverless.com
corepack enable # volta manages node/yarn versions automatically
yarn installYarn 4 workspaces hoist dependencies to the repo root (single node_modules).
2. Configure AWS profiles
# ~/.aws/config or credentials
[profile aws-drive-staging-admin]
# ... sufficient for dev + staging
[profile aws-drive-prod-admin]
# ... required for prod deploys onlyDo not change profile names — serverless.common.yml + the g:* scripts reference them directly.
3. Generate .env.local for a service
Each service needs a .env.local file with actual SSM parameter values for offline use:
yarn gen-env leads # default: staging profile, dev stage
yarn gen-env leads --stage staging # stage-specific params
yarn gen-env leads --profile aws-drive-prod-adminWhat gen-env does:
- Reads the service's
serverless.yml - Extracts all
ssm:/...references from function environment variables - Fetches actual values from AWS Parameter Store
- Writes
.env.localinto the service directory (gitignored — never commit)
Failed parameters are commented out in the generated file.
4. Run a service offline
From inside a service folder:
cd services/leads
yarn offlineyarn offline runs the root g:offline workspace script, which:
- Starts Docker Compose (
docker compose up -d) — brings up:- SQS (elasticmq) on ports 9324 (queue) / 9325 (management)
- DynamoDB Local on port 8000
- Loads
.env.localviaDOTENV_CONFIG_PATH=.env.local+-r dotenv/config - Creates resources — queues and tables declared in the service's
serverless.ymlare provisioned locally - Seeds DynamoDB — seed data from
data/seed/*.jsonis loaded (configured inserverless.ymlcustom.serverless-dynamodb.seed) - Starts
serverless-offlinewith--reloadHandler --noAuth --verbose— API served athttp://localhost:3000(no API key checks)
The full env includes: IS_LOCAL=1, NODE_ENV=development, source maps, AWS_XRAY_context_missing=LOG_ERROR.
DLQs are excluded in local mode via serverless-if-else (offline doesn't work with DLQs).
Overriding defaults
All g:* scripts resolve the AWS profile and region from env vars with sensible defaults:
| Variable | Default | Used for |
|---|---|---|
AWS_PROFILE_NAME | aws-drive-staging-admin (dev/staging), aws-drive-prod-admin (prod) | AWS auth |
SLS_REGION | ap-southeast-2 | deploy region |
APIG_SERVE_HOSTNAME | localhost:3000 | offline API hostname |
Override by exporting before the command:
AWS_PROFILE_NAME=my-custom-profile yarn offline
SLS_REGION=us-east-1 yarn deployPer-service commands
Run from inside a service folder (e.g. services/leads/). Each service package.json defines clean aliases that delegate to the root g:* workspace scripts:
| Command | Action |
|---|---|
yarn offline | Run offline (Docker DynamoDB/SQS + serverless-offline) |
yarn test | Unit tests |
yarn test:watch | Unit tests (watch mode) |
yarn deploy | Deploy to dev (alias: yarn deploy:dev) |
yarn deploy:staging | Deploy to staging |
yarn deploy:prod | Deploy to prod (prod profile) |
yarn info | Stack info |
yarn package | Package CFN (no deploy) |
yarn prune | Clean old deployments |
yarn remove | Remove the stack |
Docs site (separate package)
cd docs/site
GH_REGISTRY_TOKEN="${GH_REGISTRY_TOKEN:-dummy}" yarn install
yarn dev # http://localhost:3210See Cloudflare Pages for hosting.
Troubleshooting
Environment variable not found (GH_REGISTRY_TOKEN)— export beforeyarn install/yarn <script>. The root.yarnrc.ymlrequires it for the@caradvicescope.- DynamoDB/SQS not starting — ensure Docker is running.
docker compose up -dis called automatically byyarn offline. - DLQ errors offline — expected; DLQs are excluded in local mode. If a service declares a DLQ, it's skipped via
serverless-if-else. - Wrong Node/Yarn version — ensure Volta is installed (
volta -v). It pins versions automatically.