latest run 54 pass 0 fail 0 skipevidence →
HKB Operations: pages
HKB OperationsKnowledge space

Starred pages

Pages

Page directory · Labels · [ hides this

Cost cutoff

If CloudFront charges in Prod pass $5 in a month, a Lambda function disables the site's distribution: a traffic flood takes the site dark instead of running up the bill.

Flow

Cost cutoff flowCloudFront charges in the Prod account count against the hkb-site-cloudfront AWS Budgets budget of $5 a month. When actual spend passes 100%, Budgets publishes to an encrypted SNS topic, which invokes the hkb-site-cutoff Lambda function. The function reads the distribution ID from the site stack's outputs and sets the distribution's Enabled flag to false. That call is a CloudTrail event, which an EventBridge rule forwards to the central bus in the Security account, and the security mailbox gets an email.AWS CloudProd · hkb-prodSecurityCloudFrontthe site distributionAWS Budgets$5 a monthCutoff topicown KMS keyhkb-site-cutoffpython3.13, arm64Site stackoutputs: distribution IDEventBridge ruleforwards the callCentral bussecurity eventsSecurity mailboxemailTurning it back on is a manual step after reading the month's usage, or SiteOnline through the pipeline.The budget alerts once a month, so the cutoff can't fire again until the next.Legend1Request or run orderRequest / dataEvent / logSpend cutoffBlueOpens its pagespend1over 100%2invokes3reads4Enabled = false5CloudTrail6forwardsemail7
Cost cutoff flowOpen full sizeClose

The numbers trace one cutoff, from the budget alert to the email that says the site went dark.

Configuration

SettingValue
Budgethkb-site-cloudfront: monthly cost budget of $5 on Amazon CloudFront, alerting on actual spend over 100%
TopicAn SNS topic encrypted under its own KMS key, which only AWS Budgets may publish to
Functionhkb-site-cutoff, python3.13 on arm64, 128 MB, 60 s. It reads the distribution ID from the site stack's outputs and sets Enabled to false; if it is already off, it does nothing
Rolehkb-site-cutoff: read the site stack, and get and update only a distribution tagged Component: site
AlertThe function's UpdateDistribution call is forwarded to the central bus in Security and emailed as a security event
Turning it back onA manual step (H-12.6) after reading the month's usage, or a SiteOnline change through the pipeline. The budget alerts once a month, so it can't fire again until the next
Why a functionAWS Budgets actions can apply IAM or SCP policies and stop EC2 or RDS, but they can't disable a CloudFront distribution
Deployed byThe hkb-baseline-site-cutoff StackSet, to Prod only

Sources

  • Templates and scripts: baseline/hkb-baseline-site-cutoff.yaml, scripts/hand/site-cutoff.sh
  • Decisions: DQ-123, DQ-126

Page information

Owner
Platform Engineering
Status
current Current: generated from the templates and records in the repository at this build.
Generated from
baseline/hkb-baseline-site-cutoff.yaml
Linked from
Prod, Site distribution