Skip to Content
Self-HostingEngine on AWS

Deploy the Buildpad Engine on AWS

This page runs the Buildpad Engine in your own AWS account: one EC2 instance with Docker Compose, an S3 bucket for files, and an Application Load Balancer with your certificate. The instance runs PostgreSQL, Valkey, the Engine server and its scheduler, and optionally the DaaS Studio. Plan on half a day for a first setup.

The layout, the containers and their memory limits are the ones that Buildpad-hosted Engine projects run with.

What Runs Where

The Engine is the project’s backend: the data API, the sign-in, the files, the hooks and cron jobs, and the MCP server. It owns its database and its migrations. The Studio is the administration interface. The browser that shows the Studio sends its API calls directly to the Engine. See Run the Studio on the Buildpad Engine.

ContainerImageRunsMemory limit
engine-serverthe Engine image/app/buildpad-daas server, port 8080832 MB
engine-schedulerthe Engine image/app/buildpad-daas cron worker320 MB
engine-dbpostgres:16.4-alpinePostgreSQL 16, database buildpad_daas832 MB
engine-cachevalkey/valkey:8.0-alpineValkey: sessions, token revocation, the permission cache256 MB
studio (optional)the Studio imagethe administration interface, port 3000448 MB
one-time stepsthe Engine image/app/migrate platform up, /app/migrate tenants up, /app/seed-daas512 MB

Only the load balancer is public. The database and the cache sit on a Docker network with no route out, and the Engine reaches S3 through the instance’s role, with no access keys.

Before You Start

You need:

  • An AWS account where you can create EC2, IAM, S3 and load balancer resources.
  • Two host names, for example api.example.com for the Engine and studio.example.com for the Studio.
  • An EC2 instance size. The long-running containers add up to about 2.7 GB of memory limits. Use at least a t4g.medium (2 vCPU, 4 GiB), and a t4g.large (8 GiB) for production. The Engine image is built for both arm64 and amd64, so Graviton and Intel types both work. Give the instance an encrypted gp3 root volume of at least 30 GiB.
  • Software on the instance: Docker Engine, the Docker Compose v2 plugin, and the AWS CLI. Amazon Linux 2023 includes the AWS CLI.

Generate these secrets. Make each one fresh, and keep it in AWS Secrets Manager or in SSM Parameter Store as a SecureString. Never reuse a value from a development compose file.

SecretUsed asHow to make it
PostgreSQL superuser passwordPOSTGRES_PASSWORD, and the migrate platform stepopenssl rand -hex 32
App database passwordthe daas_app login in DATABASE_URLopenssl rand -hex 32
Migrator database passwordthe daas_migrator login for migrate tenantsopenssl rand -hex 32
Token signing keyJWT_SECRET and AUTH_ACCESS_TOKEN_SECRET_KEYopenssl rand -base64 48
Refresh token keyAUTH_REFRESH_TOKEN_SECRET_KEY, different from the signing keyopenssl rand -base64 48
MFA keyMFA_ENCRYPTION_KEY. Never change it once users enrolopenssl rand -base64 32
Host administrator passwordthe password of admin@buildpad.ai, given to the seed step once. At most 72 bytesa password manager

Hex passwords need no URL encoding in a postgres:// address. If you make a database password another way, URL-encode it in DATABASE_URL.

1. Get the Engine Image

Copy the Engine image into an Amazon ECR repository in your own account, so that your instance never pulls from Buildpad when it runs. Each Engine version is published once and is never overwritten.

The Engine image is not public. Contact Buildpad support for the version to run and for access to the image. Support can do one of two things:

  • Give your account pull access to the buildpad-daas-go repository, and send you its address. You copy the version into your own repository with the commands below.
  • Push the version into a repository you create and give Buildpad access to.

With pull access, create your repository, sign in to both registries, and copy the image. docker buildx imagetools create copies both architectures:

aws ecr create-repository --repository-name buildpad-daas-go --image-scanning-configuration scanOnPush=true aws ecr get-login-password --region <buildpad-region> | docker login --username AWS --password-stdin <buildpad-registry> aws ecr get-login-password --region <your-region> | docker login --username AWS --password-stdin <your-account>.dkr.ecr.<your-region>.amazonaws.com docker buildx imagetools create \ --tag <your-account>.dkr.ecr.<your-region>.amazonaws.com/buildpad-daas-go:<version> \ <buildpad-registry>/buildpad-daas-go:<version>

Check what you copied. This prints the version and nothing else:

docker run --rm <your-image> /app/buildpad-daas version

In the compose file, pin the image by its digest (@sha256:…), so that a pull can never change it.

2. Create the AWS Resources

Create these in one region, in a VPC with at least two subnets in different Availability Zones. The load balancer needs two.

  1. An S3 bucket for the files. Keep Block Public Access on, and turn on default encryption (SSE-S3) and versioning. Clients never reach the bucket: downloads and uploads go through the Engine, so the bucket needs no CORS rule. Choose a key prefix for this Engine, for example engine/. See File Storage on S3.
  2. An IAM role for the instance, with:
    • AmazonSSMManagedInstanceCore, so that you reach the instance with Session Manager and open no SSH port.
    • Read access to your ECR repository: AmazonEC2ContainerRegistryReadOnly, or a policy for that repository only.
    • The S3 policy below, for the Engine’s prefix only.
  3. Security groups. The load balancer: inbound 443, and 80 to redirect, from the internet. The instance: inbound 8080 and 3000 from the load balancer’s security group only. Nothing else inbound.
  4. The EC2 instance, in a private subnet, with the role above. Set IMDSv2 to required, with a hop limit of 2.
  5. A certificate and a load balancer. Request an ACM certificate for both host names. Create an Application Load Balancer with an HTTPS listener and two target groups: the Engine on port 8080, with the health check /api/health, and the Studio on port 3000, with the health check /api/server/ping. Route by host name. Set the idle timeout to at least 120 seconds, for large uploads.

With the default IMDS hop limit of 1, the Engine inside its container cannot reach the instance’s role, and file storage fails.

The S3 policy, with your bucket and prefix:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["s3:GetObject", "s3:PutObject", "s3:DeleteObject", "s3:AbortMultipartUpload", "s3:PutObjectTagging"], "Resource": "arn:aws:s3:::<bucket>/engine/*" }, { "Effect": "Allow", "Action": "s3:ListBucket", "Resource": "arn:aws:s3:::<bucket>", "Condition": { "StringLike": { "s3:prefix": "engine/*" } } } ] }

The Engine tags every image transform result with buildpad-kind=rendition. A lifecycle rule on that tag can expire their old versions sooner than your other files.

3. Configure the Engine

On the instance, make /opt/buildpad/engine/env/ owned by root with mode 0700, and write five environment files there, each with mode 0600. Fill them from your secret store when the instance starts. Do not put secrets in an AMI. Write each value as it is: no quotes, and no ${}.

engine.env is read by the server and the scheduler:

engine.env
APP_ENV=production APP_NAME=buildpad-daas APP_HOST=0.0.0.0 APP_PORT=8080 LOG_OUTPUT_MODE=json PUBLIC_URL=https://api.example.com DATABASE_URL=postgres://daas_app:<app database password>@engine-db:5432/buildpad_daas?sslmode=disable VALKEY_ENABLED=true VALKEY_URL=redis://engine-cache:6379/0 JWT_SECRET=<token signing key> AUTH_ACCESS_TOKEN_SECRET_KEY=<token signing key> AUTH_REFRESH_TOKEN_SECRET_KEY=<refresh token key> MFA_ENCRYPTION_KEY=<mfa key> STORAGE_DRIVER=s3 AWS_REGION=<region> AWS_S3_BUCKET=<bucket> STORAGE_S3_ROOT=engine/ CORS_ALLOWED_ORIGINS=https://studio.example.com,https://app.example.com CORS_ALLOW_CREDENTIALS=false TRUSTED_PROXY_CIDRS=<the CIDRs of the load balancer's subnets> GOGC=200 DB_MAX_PARALLEL_WORKERS_PER_GATHER=0

The other four files:

FileForContents
postgres.envengine-dbPOSTGRES_USER=postgres, POSTGRES_PASSWORD=<superuser password>, POSTGRES_DB=buildpad_daas
migrate-platform.envmigrate platform upAPP_ENV=production, DB_DRIVER=postgresql, DB_HOST=engine-db, DB_PORT=5432, DB_USERNAME=postgres, DB_PASSWORD=<superuser password>, DB_SCHEMA=buildpad_daas, DB_SSLMODE=disable, DB_MAX_CONNS=4, DB_MIN_CONNS=0, MIGRATE_URL=file://database/migration
migrate.envmigrate tenants upThe same as migrate-platform.env, with DB_USERNAME=daas_migrator and DB_PASSWORD=<migrator password>
seed.envseed-daasAPP_ENV=production, and DATABASE_URL with the same value as in engine.env

Notes on the settings:

  • No access keys. Do not set AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY: the Engine uses the instance’s role. Setting only one of the two stops the Engine.
  • TRUSTED_PROXY_CIDRS lets the Engine read the client’s address from the load balancer’s header. Rate limits and logs use that address. When it is empty, every request seems to come from the load balancer.
  • CORS_ALLOWED_ORIGINS lists the Studio and every web app that calls the API. When it is empty, any origin is allowed. CORS_ALLOW_CREDENTIALS=true with any origin stops the Engine when it starts. See CORS.
  • An invalid setting stops the Engine with exit code 78 and a log line that names the variable, never its value.
  • Optional settings: password-reset mail (AUTH_PASSWORD_RESET_URL, MAIL_DRIVER=smtp and MAIL_SMTP_*; Amazon SES SMTP works), sign-in with an identity provider (AUTH_EXTERNAL_*), and the upload limit (APP_MAX_UPLOAD_BYTES, 100 MiB by default). See Engine Settings. Leave BUILDPAD_SSO_SECRET unset: it is only for projects that the Buildpad platform opens.

4. Start the Stack

Save this file as /opt/buildpad/engine/compose.yaml. Replace <engine image> with your ECR image, pinned by its digest.

compose.yaml
name: buildpad-engine x-service: &service restart: unless-stopped logging: { driver: json-file, options: { max-size: 10m, max-file: "3" } } x-oneshot: &oneshot restart: "no" profiles: [oneshot] networks: [engine-internal] logging: { driver: json-file, options: { max-size: 10m, max-file: "3" } } networks: engine-internal: { internal: true } engine-edge: { driver: bridge } services: engine-db: <<: *service image: public.ecr.aws/docker/library/postgres:16.4-alpine container_name: engine-db mem_limit: 832m shm_size: 256m env_file: [/opt/buildpad/engine/env/postgres.env] volumes: [/var/lib/buildpad-engine/postgres:/var/lib/postgresql/data] networks: [engine-internal] healthcheck: { test: [CMD, pg_isready, -U, postgres, -d, buildpad_daas], interval: 5s, timeout: 3s, retries: 20 } engine-cache: <<: *service image: public.ecr.aws/valkey/valkey:8.0-alpine container_name: engine-cache mem_limit: 256m command: [valkey-server, --appendonly, "yes", --appendfsync, everysec, --save, "", --maxmemory, 100mb, --maxmemory-policy, noeviction] volumes: [/var/lib/buildpad-engine/valkey:/data] networks: [engine-internal] engine-migrate-platform: <<: *oneshot image: <engine image> mem_limit: 512m command: [/app/migrate, platform, up] env_file: [/opt/buildpad/engine/env/migrate-platform.env] engine-migrate-tenants: <<: *oneshot image: <engine image> mem_limit: 512m command: [/app/migrate, tenants, up] env_file: [/opt/buildpad/engine/env/migrate.env] engine-seed: <<: *oneshot image: <engine image> mem_limit: 256m command: [/app/seed-daas] env_file: [/opt/buildpad/engine/env/seed.env] engine-server: <<: *service image: <engine image> container_name: engine-server mem_limit: 832m command: [/app/buildpad-daas, server] env_file: [/opt/buildpad/engine/env/engine.env] environment: { DB_MAX_CONNS: "20", DB_MIN_CONNS: "2", GOMEMLIMIT: 664MiB } networks: [engine-internal, engine-edge] ports: ["8080:8080"] engine-scheduler: <<: *service image: <engine image> container_name: engine-scheduler mem_limit: 320m command: [/app/buildpad-daas, cron, worker] env_file: [/opt/buildpad/engine/env/engine.env] environment: { DB_MAX_CONNS: "5", DB_MIN_CONNS: "1", GOMEMLIMIT: 256MiB } networks: [engine-internal]

Then run these steps once, in this order, from /opt/buildpad/engine. The commands read the passwords from shell variables, which you fill from your secret store.

  1. Start the database and the cache. Wait until docker compose ps shows engine-db as healthy.

    docker compose up -d engine-db engine-cache
  2. Run the platform migration as the superuser. It creates the schema and the daas_app and daas_migrator roles, which cannot sign in yet.

    docker compose run --rm engine-migrate-platform
  3. Give the two roles the passwords from your environment files. The statements go on standard input, so they never appear in a process list.

    printf "ALTER ROLE daas_app WITH LOGIN PASSWORD '%s';\nALTER ROLE daas_migrator WITH LOGIN PASSWORD '%s';\n" "$APP_DB_PASSWORD" "$MIGRATOR_DB_PASSWORD" | docker exec -i engine-db psql -U postgres -d buildpad_daas -v ON_ERROR_STOP=1
  4. Run the tenant migration as the migrator.

    docker compose run --rm engine-migrate-tenants
  5. Create the host administrator, admin@buildpad.ai. The seed step reads the password from the first line of standard input and refuses a terminal, so keep -T. When you run it again later, it changes nothing.

    printf '%s\n' "$HOST_ADMIN_PASSWORD" | docker compose run -T --rm engine-seed
  6. Start the Engine.

    docker compose up -d engine-server engine-scheduler

Projects and static tokens (optional). One Engine can hold several projects, also called tenants. See Host and Tenants. For a server-to-server token that needs no sign-in, pipe the token into docker exec -i engine-server /app/buildpad-daas identity set-token --email <address> --tenant <project id> --kind data.

5. Add the Studio (Optional)

Run the Studio if your team wants the administration interface. Your apps do not need it: they call the Engine directly. Get the Studio image the same way as the Engine image, at the Studio version that Buildpad support pairs with your Engine version.

Write /opt/buildpad/engine/env/studio.env:

studio.env
DAAS_BACKEND=go DAAS_GO_URL=https://api.example.com NEXT_PUBLIC_BUILDPAD_DAAS_URL=https://api.example.com HOST_ORIGIN=https://studio.example.com WEB_CONCURRENCY=1 NEXT_PUBLIC_SUPABASE_URL=http://supabase.invalid NEXT_PUBLIC_SUPABASE_ANON_KEY=buildpad-engine-studio-placeholder SUPABASE_SERVICE_ROLE_KEY=buildpad-engine-studio-placeholder

The three Supabase lines are placeholders. The Studio needs them to be present but does not use them on the Buildpad Engine backend. Add this service to compose.yaml, then run docker compose up -d studio:

studio: <<: *service image: <studio image> container_name: studio mem_limit: 448m env_file: [/opt/buildpad/engine/env/studio.env] networks: [engine-edge] ports: ["3000:3000"] healthcheck: test: [CMD, node, -e, "require('http').get('http://localhost:3000/api/server/ping', r => process.exit(r.statusCode === 200 ? 0 : 1)).on('error', () => process.exit(1))"] interval: 30s timeout: 3s retries: 3 start_period: 120s

DAAS_GO_URL must be reachable from your users’ browsers, and the Studio’s origin must be in the Engine’s CORS_ALLOWED_ORIGINS. The Studio reads its settings when it starts, so a change needs docker compose up -d studio, not a new image.

6. Check the Deployment

The deployment works when these checks pass through your public host names:

CheckRequestExpected
The Engine is upGET https://api.example.com/api/health200
The database, the cache and S3 are reachableGET https://api.example.com/api/server/health200. A 503 with degraded names the part that fails, often S3 when the hop limit is 1 or the role lacks the policy
The right version runsGET https://api.example.com/api/server/infodata.project.version is the version you deployed
Sign-in worksPOST https://api.example.com/api/auth/login with {"email":"admin@buildpad.ai","password":"…"}200 with an access_token
The Studio is set upGET https://studio.example.com/api/server/healthbackend.mode is go, and engine_origin is the Engine’s address

Then open the Studio, sign in as admin@buildpad.ai, and upload a file. Check that it lands under your prefix in S3. If a container keeps restarting, docker compose logs engine-server shows the setting that stopped it.

Upgrade the Engine

Migrations only move forward, so take a backup first. To roll back, you restore that backup.

  1. Copy the new version into your ECR repository (step 1), and put its digest in compose.yaml.

  2. Take an EBS snapshot of the instance’s volume, or a database dump (see Back Up).

  3. Run both migrations, then recreate the Engine with the new image:

    docker compose run --rm engine-migrate-platform docker compose run --rm engine-migrate-tenants docker compose up -d --force-recreate engine-server engine-scheduler
  4. Repeat the checks in step 6. If they fail, stop the Engine, restore the snapshot, and put the old digest back.

Back Up

Three things hold data: the database, the Valkey directory (the sessions), and the S3 bucket. Schedule a backup for each:

  • The database: a nightly dump to a separate S3 bucket or prefix, kept for at least 14 days.

    docker exec engine-db pg_dump -U postgres -Fc -C -d buildpad_daas > buildpad_daas.dump
  • The instance’s volume: a daily EBS snapshot with Amazon Data Lifecycle Manager. It also covers /var/lib/buildpad-engine/valkey and the environment files.

  • The files: the S3 versioning that you turned on in step 2. Add a lifecycle rule for old versions.

Test a restore on a new instance before you go live.

Logs and Monitoring

The Engine writes JSON logs to standard output, and the compose file keeps three files of 10 MB per container. Send them to CloudWatch Logs with the CloudWatch agent or the awslogs log driver. Set alarms on the load balancer’s unhealthy host count, on disk use above 80%, and on memory.

Never set an eviction policy on Valkey. An evicted key can bring back a revoked token.

Security Checklist

  • Every secret is new, kept in Secrets Manager or SSM, and absent from the AMI and from git.
  • The instance has no public IP address, and no inbound rule except from the load balancer.
  • IMDSv2 is required, with a hop limit of 2.
  • The S3 bucket blocks public access, is encrypted and versioned, and the role reaches only the Engine’s prefix.
  • The EBS volume is encrypted.
  • CORS_ALLOWED_ORIGINS names your origins. It is not empty.
  • The host administrator’s password is in a password manager, and MFA_ENCRYPTION_KEY is set and backed up.
  • The backups run, and a restore has been tested.

See also Security.