TrayPage Docs

Self-hosting on AWS

The key points of running TrayPage in your own AWS account (Fargate + RDS with Terraform), and what to do if you want a single EC2 instance.

This page explains how to run TrayPage in your own AWS account, so your data stays there. The Terraform module for it lives under deploy/aws/terraform in the repository. This page covers how to decide and the key steps. The full variable list and the detailed commands are in the README.

If you want to try it cheaply on a single EC2 instance, see Running on a single EC2 instance.

The setup

Standard (Fargate + RDS)
Built withTerraform (deploy/aws/terraform)
Good forProduction, where downtime is a problem
LayoutFargate tasks (2 by default) behind an ALB, with the database on RDS
RedundancySpread across multiple AZs. RDS is Multi-AZ by default
Database backupsRDS automated backups (7 days by default)
Operational effortMedium to high (you manage Terraform)
Rough costAbout $200 per month for the default setup, about $125 for the small setup

The cost is an estimate for the Tokyo region (ap-northeast-1) at on-demand prices. It varies with data transfer and request volume. The breakdown:

  • The NAT Gateway is about $45. It carries outbound traffic such as pulling the image and sending email.
  • Making RDS Multi-AZ exactly doubles the instance and storage cost.
  • The small setup uses one Fargate task and a single-AZ db.t4g.micro RDS instance. It is meant for evaluation and has no redundancy.

Check exact amounts with the AWS Pricing Calculator.

Prerequisites

  • Two domain names: one for the app and one for the viewer. The viewer host serves arbitrary HTML, so it must be a different host name from the app. If possible, use separate domains (for example traypage.example.com and traypage-content.example.net). See Security notes for the reason.
  • A way to send email, and a sender address: sign-in uses an emailed link. The setup uses SES (SMTP). SES requires verifying the sender domain and requesting production access (leaving the sandbox). Until that is approved, login emails reach only addresses you have verified in SES. The sender (email_from) is required, and must be an address on the domain you verified in SES.
  • An AWS account and permissions: permission to create VPC, ECS, RDS, S3, IAM, Secrets Manager, SES, ACM, and Route 53 resources.
  • An ACM certificate: the ALB uses a certificate that covers both host names. If you have a Route 53 hosted zone, Terraform creates it, including the DNS validation. Without a hosted zone, prepare a certificate in the same region as the ALB and pass it as certificate_arn. In that case you point DNS at the ALB yourself.

Key steps

  1. Prepare the prerequisites: Terraform 1.5 or later, AWS credentials, two host names, DNS and a certificate, and an SES sender domain.
  2. Create a variables file from the bundled example (examples/standard). The required variables are image_tag, app_hostname, viewer_hostname, and email_from. If you use Route 53, also set route53_zone_id.
    • To use an image you copied to ECR, set image_repository to the ECR URI. Terraform grants the permission to pull it.
    • On an AWS Free plan account, RDS cannot be created with the defaults. Set db_instance_class = "db.t4g.micro", db_multi_az = false, and db_backup_retention_days = 1.
  3. Run terraform init, terraform plan, and terraform apply. The first run takes 20 to 30 minutes. For production, keep the state in an encrypted S3 backend, because it contains values such as the database password.
  4. Leave the SES sandbox, then check /health, sign-in, and the MCP connection.

The client IP address is the value the ALB appends to the end of X-Forwarded-For. The module sets TRUSTED_CLIENT_IP_HEADER=x-forwarded-for and ENVIRONMENT=production, so no extra configuration is needed. If you add CloudFront or similar in front of the ALB, you need a setting that passes on the client IP added by that layer.

The app creates and updates the database tables itself at startup. Terraform only creates an empty database and a user, so a deployment involves no database work. A task whose migration fails does not start, and ECS rolls back to the previous task definition.

Updates, backups, and deletion

  • Updates: set image_tag to the new version and run terraform apply. ECS replaces tasks by stopping the old ones only after the new ones are healthy. Take an RDS snapshot before updating. Migrations cannot be reversed, so to go back to an older version you restore the database from the snapshot.
  • Backups: use RDS automated backups (7 days by default) and manual snapshots. Page content is protected by S3 versioning.
  • Deletion: the ALB and RDS have deletion protection, and the page content bucket cannot be deleted while it has contents. First save the data you want to keep (an RDS snapshot, the bucket contents) and check that you are about to delete the right environment (the account, the region, and the bucket and database names in terraform output). Then add deletion_protection = false and s3_force_destroy = true (deletes the page content along with the bucket) to your variables file, apply them with terraform apply, and run terraform destroy. Deletion takes 8 to 10 minutes. The following remain, so delete them by hand if you do not need them.
    • The final RDS snapshot.
    • The Secrets Manager secrets (kept in a pending-deletion state for 7 days by default, during which the same names cannot be reused).
    • The log group for RDS logs (/aws/rds/instance/<name>/postgresql).

It runs as the self-hosted edition

The Terraform module runs the app as the self-hosted edition. It differs from tray.page (hosted) in these ways.

  • Opening / takes you to the sign-in screen (or to the app if you are signed in). The tray.page landing page is not shown.
  • The pages meant for tray.page (pricing, terms, privacy policy, and the contact form) do not exist (they return 404). The documentation (/docs) is served.
  • There are no usage limits, such as the number of pages, and no trials.
  • The tray.page sender address is never used for email. You must set email_from to an address on your own domain.

No keys for S3

The S3 bucket for page content is accessed without access keys. The Fargate task role is granted permission for that bucket only. The app obtains the role's temporary credentials and uses them to access S3. This is switched on by the environment variable S3_USE_IAM_ROLE=1, which the module sets for you. No secret needs to be stored on the server.

The one exception is SES SMTP: SES requires an SMTP password derived from an IAM user's key. Terraform creates an IAM user allowed to do nothing but send email, and passes the password to the app through Secrets Manager.

Running on a single EC2 instance

If you want to try TrayPage cheaply or run it small on a single EC2 instance, follow the Docker / VPS steps on an EC2 instance you create yourself. A dedicated template (CloudFormation) for a single EC2 instance existed before, but it is no longer provided.

These points are specific to AWS. This combination has not been verified on a real instance.

  • Inbound access: open ports 80 and 443 in the security group. Attach an Elastic IP so the address does not change.
  • Disk: by default, the database, page content, and certificates live on the instance's root EBS volume. By default, the root volume is deleted when the instance is terminated.
  • Page content on S3: with the settings in Using external Postgres and S3, you can point page content at an S3 bucket. Set S3_USE_INSTANCE_ROLE=1 to use the instance's IAM role instead of keys (grant the role read and write access to that bucket, and set the instance metadata option HttpPutResponseHopLimit to 2 or more).
  • Backups: take the pg_dump in Backup and restore regularly, and keep it off the instance (for example in S3).