# hkb-forward-site-cutoff-errors

Fires on: The site cutoff function failing.

Run the [common pre-checks](/wiki/runbooks/#common-pre-checks) first.

## Symptoms
An email from `hkb security alert` for the CloudWatch alarm `hkb-site-cutoff-errors` going to ALARM in Prod. The `hkb-site-cutoff` function returned an error, so the cost cutoff may have failed. The site may keep serving past its CloudFront budget.

## Pre-checks
1. Read the function's log group, `/aws/lambda/hkb-site-cutoff`, as HKB-ReadOnly (`ro-hkb-prod`) for the error and its stack trace.
2. Check whether the distribution is still enabled: `aws cloudfront get-distribution --profile ro-hkb-prod --id <id>`. `Enabled: false` means a retry worked, and the [cutoff runbook](/wiki/runbooks/members/hkb-forward-site-cutoff/) applies instead.
3. Read the month's CloudFront usage in Cost Explorer (`ro-hkb-master`) to judge how urgent the stop is.

## Resolution
- **Spend is still climbing:** take the site off by hand first. A `SiteOnline` pull request to false disables the distribution through the pipeline (DQ-68). Kyle runs that step.
- **Then fix the function:** correct the cause in `baseline/hkb-baseline-site-cutoff.yaml` (a permission, the distribution ID, a code error) and deploy it through the pipeline.
- **Prove the fix:** manual step H-12.7, `site-cutoff.sh test`, publishes to the cutoff topic on the budget's path. The function should disable the distribution and the cutoff alert should follow. Restore with H-12.6.

## Post-checks
The alarm returns to OK, the function's last run in the log group shows no error, and the cutoff alert arrived after the test. The live check passes once the site is back on.

## Rollback
Revert the function's PR and deploy again. Leave the site off until the cutoff works.

## Alert details

| Property | Value |
| --- | --- |
| Runs in | Prod, us-east-1, forwarded to the `hkb-security-events` bus in Security |
| Email | From `hkb security alert`: `SECURITY EVENT <src> <what> in account <account>, <region>, at <time> by <who>.` |
| Source | `baseline/hkb-baseline-site-cutoff.yaml`, resource `CutoffErrorsForwardRule` |

The event pattern, as deployed:

```yaml
EventPattern:
  source: [aws.cloudwatch]
  detail-type: [CloudWatch Alarm State Change]
  detail:
    alarmName: [hkb-site-cutoff-errors]
    state:
      value: [ALARM]
```
