Skip to main content

Infrastructure

Every AWS resource is defined in AWS CDK (TypeScript) in infra/ (ADR 0008). A few things were made by hand and live outside the code: the GitHub deploy role, the caretosher.com hosted zone, and the email subscriptions on the two alarm topics (Alarms).

Stacks​

infra/bin/app.ts creates one set of stacks per stage, named CaregiverDev-… or CaregiverProd-…:

StackFileWhat it owns
Sharedshared-stack.tsThe 13 DynamoDB tables (v1TableSpecs), the Cognito user pool and app client, AppConfig flags, the alarm SNS topic.
Apiapi-stack.tsThe API Lambda and its live alias, the HTTP API with its routes and JWT authorizer, the api(-dev).caretosher.com domains (plus the legacy api-v2(-dev) names), the feedback topic, and the generator Lambda with its daily schedule.
Observabilityobservability-stack.tsThe alarms and the dashboard. See Support.
Web (us-east-1)web-stack.tsThe S3 bucket, CloudFront distribution and certificate for caretosher.com.
Billing (prod only, us-east-1)billing-stack.tsA CloudWatch spend alarm and an overall monthly budget.

Web is in us-east-1 because CloudFront only takes certificates from there, and Billing because AWS publishes billing metrics only there. Everything else is in us-east-2.

Stacks share values through CloudFormation exports (for example, Api uses the tables Shared creates). Removing something a deployed stack still imports takes two deploys: first stop using it, then remove it.

Prod tables use RemovalPolicy.RETAIN, so deleting one from the code leaves the table (and its data) in AWS until it is deleted by hand. Dev tables are destroyed with the stack.

Stages and deploys​

(ADR 0004)

  • Dev: every push to an open pull request runs ci-pr.yml, which tests everything and deploys all stacks with --context stage=dev. Two open PRs overwrite each other's dev deploy.
  • Prod: every merge to main runs cd-main.yml, which tests again and deploys with --context stage=prod. There is no manual approval step, so merging is deploying.

GitHub Actions signs in to AWS through OIDC, as the CaregiverGitHubDeploy role.

Working on it​

cd infra && pnpm test # unit tests (template assertions)
cd infra && pnpm exec cdk synth --context stage=dev # render the CloudFormation
cd infra && pnpm exec cdk diff --context stage=dev # compare with what is deployed

A prod synth also needs CAREGIVER_ALERT_EMAIL set: the address the monthly AWS budget emails (alarm emails go to the topics' own subscriptions). CI posts a cdk diff on each pull request.