Skip to content

Commit e84dba6

Browse files
committed
fix(aws): restore PAYG production routing
Use pay-as-you-go CloudFront, cap the worker fleet at 50, accept ALB hostnames at the TLS proxy, and prevent ineligible jobs from driving autoscaling.
1 parent 7d0c0e1 commit e84dba6

9 files changed

Lines changed: 31 additions & 86 deletions

File tree

.github/workflows/deploy-aws.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,13 @@ jobs:
268268
aws ecs wait services-stable --cluster "$cluster" --services "$service"
269269
done
270270
271-
- name: Verify public health and flat-rate gate
271+
- name: Verify public media pipeline
272272
if: ${{ inputs.apply && inputs.services_enabled }}
273273
working-directory: infra/aws/platform
274274
env:
275275
REND_READINESS_API_KEY: ${{ secrets.REND_READINESS_API_KEY }}
276276
run: |
277277
set -euo pipefail
278-
test "$(terraform output -raw cloudfront_flat_rate_plan_verified)" = true
279278
api_url="$(terraform output -raw api_url)"
280279
playback_url="$(terraform output -raw playback_url)"
281280
curl --fail --silent --show-error "$api_url/readyz" >/dev/null

docs/deployment-aws.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,11 @@ must activate this tag when Rend runs in a linked account. Service, worker,
170170
storage, and organization hard ceilings remain active while the Budget is
171171
pending; set the flag true and apply again as soon as the tag is active.
172172

173-
Production planning is also gated by
174-
`cloudfront_flat_rate_plan_verified = true`. Set it only after AWS shows the
175-
Business flat-rate plan active in account `211125561119`; VPC Origins require
176-
Business or Premium. Terraform cannot activate the commercial plan itself. A
177-
brand-new distribution therefore has one explicit bootstrap apply: set
178-
`cloudfront_flat_rate_plan_bootstrap = true`, apply, subscribe the distribution
179-
to Business in the CloudFront console, then immediately set bootstrap false and
180-
verification true before the next apply.
173+
CloudFront remains on pay-as-you-go pricing. Playback is authenticated and WAF
174+
protected, while cost and abuse exposure is controlled by server-side quotas,
175+
queue admission, and hard ECS autoscaling ceilings. Production keeps one media
176+
worker warm and can run at most 50 workers globally; no quota or infrastructure
177+
limit needs to be rendered in the dashboard.
181178

182179
The source and media buckets remain external to AWS but their full contract is
183180
owned by Terraform. During apply, an idempotent reconciler reads Tigris

infra/aws/README.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,9 @@ Before the first platform apply:
132132

133133
Delete local plaintext copies after storing the secret and your encrypted
134134
recovery copy.
135-
4. Activate the CloudFront Business flat-rate plan in account `211125561119`,
136-
then set `cloudfront_flat_rate_plan_verified = true`. VPC Origins require at
137-
least Business. Terraform blocks production while verification is false.
138-
For the first distribution only, set
139-
`cloudfront_flat_rate_plan_bootstrap = true` for one apply, subscribe the new
140-
distribution immediately in the CloudFront console, then set bootstrap back
141-
to false and verification to true. This escape hatch avoids an IaC/console
142-
creation deadlock and must never remain enabled.
135+
4. Keep CloudFront on pay-as-you-go pricing. Rend controls exposure through
136+
authenticated playback, WAF rules, backend quotas, and hard ECS autoscaling
137+
ceilings rather than a fixed monthly CloudFront plan.
143138
5. Obtain the production PlanetScale PrivateLink endpoint service name, set it
144139
in tfvars, and ensure the TLS database URL uses PlanetScale's private DNS.
145140
6. Add the two Route53 delegation record sets emitted by bootstrap at the
@@ -153,11 +148,11 @@ Before the first platform apply:
153148
`Application=rend`; an account-wide budget is intentionally forbidden in
154149
this shared account.
155150

156-
The Business plan is $200/month with no traffic overage charges. The remaining
157-
default cost envelope is guarded by a $400 monthly AWS alert budget, 50 videos
158-
and 10 open uploads per organization, two active media jobs per organization,
159-
and at most ten 4-vCPU/8-GiB workers. ClickHouse starts with 100 GiB encrypted
160-
gp3.
151+
CloudFront is pay-as-you-go. The default cost envelope is guarded by a $400
152+
monthly AWS alert budget, 50 videos and 10 open uploads per organization, two
153+
active media jobs per organization, and at most fifty 4-vCPU/8-GiB workers.
154+
Only one worker is kept warm; the fleet scales from queue demand. ClickHouse
155+
starts with 100 GiB encrypted gp3.
161156

162157
ClickHouse has two independent nightly recovery layers: a native database
163158
backup copied to a versioned KMS-encrypted S3 bucket at 02:15 UTC and an AWS

infra/aws/environments/production.tfvars.example

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,9 @@ api_max_tasks = 6
6565
edge_min_tasks = 2
6666
edge_max_tasks = 6
6767
worker_min_tasks = 1
68-
worker_max_tasks = 10
68+
worker_max_tasks = 50
6969

7070
cloudfront_price_class = "PriceClass_All"
71-
# VPC Origins require Business or Premium. For a brand-new distribution only,
72-
# set bootstrap=true for its first apply, immediately subscribe it to Business
73-
# in the CloudFront console, then set verified=true and bootstrap=false.
74-
cloudfront_flat_rate_plan_tier = "Business"
75-
cloudfront_flat_rate_plan_bootstrap = false
76-
cloudfront_flat_rate_plan_verified = false
7771
monthly_budget_usd = 400
7872
# Linked accounts cannot activate this tag themselves. Leave false for the
7973
# initial migration, then enable it after the Organizations management account

infra/aws/platform/compute.tf

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,7 @@ resource "aws_ecs_task_definition" "api" {
209209
essential = true
210210
entryPoint = ["/bin/sh", "-c"]
211211
command = [<<-EOT
212-
proxy_ip="$(hostname -i | awk '{print $1}')"
213-
printf '{\n auto_https disable_redirects\n admin off\n}\nhttps://%s:8443 {\n tls internal\n reverse_proxy 127.0.0.1:4000\n}\n' "$proxy_ip" >/tmp/Caddyfile
212+
printf '{\n auto_https disable_redirects\n admin off\n}\nhttps://:8443 {\n tls internal\n reverse_proxy 127.0.0.1:4000\n}\n' >/tmp/Caddyfile
214213
exec caddy run --config /tmp/Caddyfile --adapter caddyfile
215214
EOT
216215
]
@@ -352,8 +351,7 @@ resource "aws_ecs_task_definition" "edge" {
352351
essential = true
353352
entryPoint = ["/bin/sh", "-c"]
354353
command = [<<-EOT
355-
proxy_ip="$(hostname -i | awk '{print $1}')"
356-
printf '{\n auto_https disable_redirects\n admin off\n}\nhttps://%s:8443 {\n tls internal\n reverse_proxy 127.0.0.1:4100\n}\n' "$proxy_ip" >/tmp/Caddyfile
354+
printf '{\n auto_https disable_redirects\n admin off\n}\nhttps://:8443 {\n tls internal\n reverse_proxy 127.0.0.1:4100\n}\n' >/tmp/Caddyfile
357355
exec caddy run --config /tmp/Caddyfile --adapter caddyfile
358356
EOT
359357
]

infra/aws/platform/delivery.tf

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -152,21 +152,6 @@ resource "aws_cloudfront_key_group" "playback" {
152152
items = [aws_cloudfront_public_key.playback.id]
153153
}
154154

155-
resource "terraform_data" "cloudfront_flat_rate_plan_guard" {
156-
input = {
157-
bootstrap = var.cloudfront_flat_rate_plan_bootstrap
158-
tier = var.cloudfront_flat_rate_plan_tier
159-
verified = var.cloudfront_flat_rate_plan_verified
160-
}
161-
162-
lifecycle {
163-
precondition {
164-
condition = var.cloudfront_flat_rate_plan_verified || var.cloudfront_flat_rate_plan_bootstrap
165-
error_message = "Production is blocked until the CloudFront flat-rate plan is active in account 211125561119. For the first distribution apply only, explicitly set cloudfront_flat_rate_plan_bootstrap=true, subscribe immediately, then set verified=true and bootstrap=false."
166-
}
167-
}
168-
}
169-
170155
resource "aws_cloudfront_response_headers_policy" "public" {
171156
name = "${local.resource_prefix}-security"
172157

@@ -499,7 +484,6 @@ resource "aws_cloudfront_distribution" "this" {
499484
depends_on = [
500485
aws_s3_bucket_acl.cloudfront_logs,
501486
aws_s3_bucket_policy.cloudfront_logs,
502-
terraform_data.cloudfront_flat_rate_plan_guard,
503487
]
504488
}
505489

infra/aws/platform/outputs.tf

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@ output "cloudfront_playback_key_pair_id" {
1111
value = aws_cloudfront_public_key.playback.id
1212
}
1313

14-
output "cloudfront_flat_rate_plan_verified" {
15-
value = var.cloudfront_flat_rate_plan_verified
16-
}
17-
18-
output "cloudfront_flat_rate_plan_tier" {
19-
value = var.cloudfront_flat_rate_plan_tier
20-
}
21-
2214
output "api_url" {
2315
value = local.api_base_url
2416
}

infra/aws/platform/variables.tf

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,12 @@ variable "worker_min_tasks" {
372372

373373
variable "worker_max_tasks" {
374374
type = number
375-
default = 10
375+
default = 50
376376

377377

378378
validation {
379-
condition = var.worker_max_tasks >= 1 && var.worker_max_tasks <= 10
380-
error_message = "worker_max_tasks must be between 1 and the hard ceiling of 10."
379+
condition = var.worker_max_tasks >= 1 && var.worker_max_tasks <= 50
380+
error_message = "worker_max_tasks must be between 1 and the hard global ceiling of 50."
381381
}
382382
}
383383

@@ -425,29 +425,6 @@ variable "cloudfront_price_class" {
425425
}
426426
}
427427

428-
variable "cloudfront_flat_rate_plan_verified" {
429-
description = "Explicit production gate confirming the AWS account has an active CloudFront flat-rate plan."
430-
type = bool
431-
default = false
432-
}
433-
434-
variable "cloudfront_flat_rate_plan_tier" {
435-
description = "Selected CloudFront flat-rate tier. VPC Origins require Business or Premium."
436-
type = string
437-
default = "Business"
438-
439-
validation {
440-
condition = contains(["Business", "Premium"], var.cloudfront_flat_rate_plan_tier)
441-
error_message = "The Rend VPC Origin requires the Business or Premium CloudFront flat-rate tier."
442-
}
443-
}
444-
445-
variable "cloudfront_flat_rate_plan_bootstrap" {
446-
description = "One-apply escape hatch used only to create a new distribution before subscribing it to a plan in the CloudFront console."
447-
type = bool
448-
default = false
449-
}
450-
451428
variable "tls_proxy_image" {
452429
description = "Pinned Caddy image used only for self-signed TLS between the internal ALB and ECS tasks."
453430
type = string

services/rend-api/src/main.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,8 +1703,17 @@ async fn publish_media_queue_metrics(state: &AppState) -> Result<()> {
17031703
GREATEST(count(DISTINCT locked_by) FILTER (
17041704
WHERE status = 'running' AND lease_expires_at > now()
17051705
), 1)
1706-
FROM rend.media_jobs
1707-
WHERE job_type = 'process_media'
1706+
FROM rend.media_jobs job
1707+
JOIN rend.assets asset
1708+
ON asset.id = job.asset_id
1709+
AND asset.deleted_at IS NULL
1710+
AND asset.suspended_at IS NULL
1711+
JOIN rend_auth.organization org
1712+
ON org.id = asset.organization_id
1713+
AND org.suspended_at IS NULL
1714+
JOIN rend.organization_storage_usage quota
1715+
ON quota.organization_id = asset.organization_id
1716+
WHERE job.job_type = 'process_media'
17081717
",
17091718
)
17101719
.fetch_one(&state.db)

0 commit comments

Comments
 (0)