Skip to Content
Self-HostingFile Storage on S3

File Storage on S3

The Buildpad Engine keeps uploaded files on its own disk by default (STORAGE_DRIVER=local). For a self-hosted Engine, S3 is the better choice: the files survive the server, many Engines can share one bucket, and the bucket can keep earlier versions of each file.

This page sets up S3 for an Engine that you run from its Docker image. It also covers S3-compatible stores such as MinIO and Cloudflare R2.

How the Engine Uses the Bucket

  • Clients never reach the bucket. Downloads, signed URLs, signed uploads and image transforms all go through the Engine. The bucket stays private and needs no CORS rule.
  • Every object is kept under one prefix. STORAGE_S3_ROOT sets it. Give each Engine its own prefix, and many Engines can share one bucket.
  • The Engine only reads and writes objects. It never changes the bucket’s settings, its versioning or its lifecycle rules.

1. Set the Engine’s Variables

Set these on the Engine container. Set the same storage variables on every Engine container that runs the Engine’s image: the server, the cron worker and the seed. Each one checks the storage settings when it starts.

VariableRequiredValue
STORAGE_DRIVERYess3
AWS_S3_BUCKETYesThe bucket name
AWS_REGIONYes, unless AWS_S3_ENDPOINT is setThe bucket’s region. When it is empty, the Engine reads AWS_DEFAULT_REGION, then the shared AWS configuration, then the region of the EC2 instance it runs on
STORAGE_S3_ROOTNoThe key prefix for every object of this Engine, for example daas/. The trailing / is optional
AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEYOnly without a roleAn access key. Set both or neither
AWS_SESSION_TOKENNoRead only together with the two keys above
AWS_S3_ENDPOINTOnly for an S3-compatible storeThe store’s address. Do not set it for Amazon S3
AWS_S3_FORCE_PATH_STYLENotrue for path-style addresses. With AWS_S3_ENDPOINT set, the Engine always uses path-style addresses

The Engine does not read STORAGE_URL or AWS_S3_TIMEOUT.

2. Give the Engine Credentials

Choose the case that matches where the Engine runs.

On AWS: use a role

When no access key is set, the Engine uses the standard AWS credential chain. On AWS, give the Engine a role and set no key:

  • EC2: attach the role to the instance as an instance profile. The Engine runs in a container, so set the instance’s IMDSv2 hop limit to 2. With the default of 1, the container cannot reach the instance metadata service, and the Engine finds no credentials.
  • ECS: use a task role. The Engine finds it without any setting.
  • EKS: use IAM roles for service accounts. The Engine reads the web identity variables that EKS sets.

The Engine refreshes the role’s credentials before they expire.

services: engine: image: <buildpad-engine-image> environment: STORAGE_DRIVER: s3 AWS_S3_BUCKET: my-daas-files AWS_REGION: ap-southeast-1 STORAGE_S3_ROOT: daas/

Outside AWS: use an access key

Make an IAM user with the policy of step 3, make an access key for it, and pass the key to the Engine. Keep the key in a secret store or an .env file that is not committed.

services: engine: image: <buildpad-engine-image> environment: STORAGE_DRIVER: s3 AWS_S3_BUCKET: my-daas-files AWS_REGION: ap-southeast-1 STORAGE_S3_ROOT: daas/ AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID} AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}

An S3-compatible store: MinIO or Cloudflare R2

Set AWS_S3_ENDPOINT to the store’s address, and use the store’s own access key.

# MinIO STORAGE_DRIVER: s3 AWS_S3_BUCKET: daas-files AWS_S3_ENDPOINT: http://minio:9000 AWS_ACCESS_KEY_ID: ${MINIO_ACCESS_KEY} AWS_SECRET_ACCESS_KEY: ${MINIO_SECRET_KEY}
# Cloudflare R2 STORAGE_DRIVER: s3 AWS_S3_BUCKET: daas-files AWS_S3_ENDPOINT: https://<account-id>.r2.cloudflarestorage.com AWS_REGION: auto AWS_ACCESS_KEY_ID: ${R2_ACCESS_KEY_ID} AWS_SECRET_ACCESS_KEY: ${R2_SECRET_ACCESS_KEY}

With AWS_S3_ENDPOINT set and no region, the Engine signs requests for us-east-1. MinIO accepts that. Cloudflare R2 expects AWS_REGION=auto.

3. Limit the Engine to Its Prefix

Give the role or the IAM user these permissions on the Engine’s prefix only. In this example the bucket is my-daas-files and the prefix is daas/:

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

Keep the s3:ListBucket statement. With a policy limited to a prefix, S3 answers a request for a missing file with 403, not 404. The Engine uses a list request to tell a missing file from a refused one.

The Engine needs no permission on object versions and no s3:PutBucket* permission.

4. Set Up the Bucket

  • Keep it private. Turn on Block Public Access. Add no CORS rule and no public bucket policy.
  • Encryption: the default server-side encryption (SSE-S3) is enough.
  • Versioning (optional): with versioning on, a deleted or replaced file keeps its earlier version until a lifecycle rule removes it. Add a lifecycle rule that removes old versions after the number of days you need.
  • Image transform results: the Engine tags each stored transform result with buildpad-kind=rendition. The Engine can make them again at any time, so a lifecycle rule can remove their old versions sooner.

5. Check the Setup

  1. Start the Engine. It refuses to start, with exit code 78, when a storage setting is wrong: an unknown STORAGE_DRIVER, only one of the two access key variables, or no region and no endpoint. The log names the setting.
  2. Read the start-up log. The Engine logs a storage.probe record with the location, the bucket and the outcome. ok means the Engine reached the bucket with its credentials.
  3. Call the health route. GET /api/server/health on the Engine reports the file storage. A bucket that cannot be reached, or that refuses the credentials, does not stop the Engine. The health route then reports the storage as down.
  4. Upload a file. Upload a file in the Studio, and make sure an object appears under your prefix in the bucket.

Move From Local Storage

Changing STORAGE_DRIVER does not copy files that are already on the Engine’s disk. Copy them first: the files under the Engine’s STORAGE_LOCAL_PATH go under STORAGE_S3_ROOT in the bucket, with the same relative keys. Then change the settings and restart the Engine. A file record that names the local location is read from the new default location, so the file records need no change.