Deep DivesAPI

Deployment

Deployment guide for the RawStack API component.

The API is containerised and deployed to AWS ECS Fargate via the CDK infrastructure stack.

Build and push to ECR

Use the provided script from the repo root:

./scripts/push-api-to-ecr.sh
# Or with a specific tag:
./scripts/push-api-to-ecr.sh v1.2.3

The script:

  1. Reads AWS_REGION, AWS_ACCOUNT_ID, and CORE_ECR_REPOSITORY_NAME from infrastructure/aws/.env
  2. Builds the Docker image (multi-stage, Node 22 Alpine)
  3. Logs into ECR
  4. Creates the ECR repository if it doesn't exist
  5. Pushes the image

Auto-deployment

The CDK Core Stack deploys a Lambda function that listens for ECR PUSH events on the repository via EventBridge. When a new image is pushed, the Lambda triggers a new ECS deployment automatically — no manual ecs update-service required.

Dockerfile

The build uses a multi-stage Dockerfile:

  1. Builder stage — installs all dependencies, compiles TypeScript, generates Prisma client
  2. Production stage — copies only the compiled output and production node_modules, keeping the image lean

At container startup, prisma migrate deploy runs before the NestJS application starts, ensuring migrations are always applied.

Environment variables in production

Sensitive values are injected as ECS task environment variables by the CDK stack. The CDK reads them from infrastructure/aws/.env at deploy time — never bake secrets into the image.

See Infrastructure deployment for the full variable reference.

Health check

The ALB health check hits GET /health. Ensure this endpoint returns 200 before marking tasks as healthy.